CouchDB-1.2.1: CouchDB interface

Safe HaskellNone
LanguageHaskell98

Database.CouchDB

Contents

Description

Interface to CouchDB.

Synopsis

Initialization

data CouchMonad a Source

A computation that interacts with a CouchDB database. This monad encapsulates the IO monad, a persistent HTTP connnection to a CouchDB database and enough information to re-open the connection if it is closed.

runCouchDB Source

Arguments

:: String

hostname

-> Int

port

-> CouchMonad a 
-> IO a 

runCouchDB' :: CouchMonad a -> IO a Source

Connects to the CouchDB server at localhost:5984.

runCouchDBURI Source

Arguments

:: URI

URI to connect

-> CouchMonad a 
-> IO a 

Explicit Connections

data CouchConn Source

Describes a connection to a CouchDB database. This type is encapsulated by CouchMonad.

runCouchDBWith :: CouchConn -> CouchMonad a -> IO a Source

Run a CouchDB computation with an existing CouchDB connection.

createCouchConn Source

Arguments

:: String

hostname

-> Int

port

-> IO CouchConn 

Create a CouchDB connection for use with runCouchDBWith.

createCouchConnFromURI Source

Arguments

:: URI

URI with possible login credentials

-> IO CouchConn 

Create a CouchDB from an URI connection for use with runCouchDBWith.

closeCouchConn :: CouchConn -> IO () Source

Closes an open CouchDB connection

Databases

data DB Source

Database name

Instances

db :: String -> DB Source

Returns a safe database name. Signals an error if the name is invalid.

createDB :: String -> CouchMonad () Source

Creates a new database. Throws an exception if the database already exists.

dropDB Source

Arguments

:: String 
-> CouchMonad Bool

False if the database does not exist

Documents

data Doc Source

Document name

data Rev Source

Document revision number.

doc :: String -> Doc Source

Returns a safe document name. Signals an error if the name is invalid.

rev :: String -> Rev Source

Returns a Rev

newNamedDoc Source

Arguments

:: JSON a 
=> DB

database name

-> Doc

document name

-> a

document body

-> CouchMonad (Either String Rev)

Returns Left on a conflict.

newDoc Source

Arguments

:: JSON a 
=> DB

database name

-> a

document body

-> CouchMonad (Doc, Rev)

id and rev of new document

updateDoc Source

Arguments

:: JSON a 
=> DB

database

-> (Doc, Rev)

document and revision

-> a

new value

-> CouchMonad (Maybe (Doc, Rev)) 

bulkUpdateDocs Source

Arguments

:: JSON a 
=> DB

database

-> [a]

new docs

-> CouchMonad (Maybe [Either String (Doc, Rev)]) 

deleteDoc Source

Arguments

:: DB

database

-> (Doc, Rev) 
-> CouchMonad Bool 

forceDeleteDoc Source

Arguments

:: DB

database

-> Doc

document identifier

-> CouchMonad Bool 

Delete a doc by document identifier (revision number not needed). This operation first retreives the document to get its revision number. It fails if the document doesn't exist or there is a conflict.

getDocPrim Source

Arguments

:: DB

database name

-> Doc

document name

-> CouchMonad (Maybe (Doc, Rev, [(String, JSValue)]))

Nothing if the document does not exist.

Gets a document as a raw JSON value. Returns the document id, revision and value as a JSObject. These fields are queried lazily, and may fail later if the response from the server is malformed.

getDoc Source

Arguments

:: JSON a 
=> DB

database name

-> Doc

document name

-> CouchMonad (Maybe (Doc, Rev, a))

Nothing if the doc does not exist

getAllDocs Source

Arguments

:: JSON a 
=> DB 
-> [(String, JSValue)]

query parameters

-> CouchMonad [(Doc, a)] 

getAndUpdateDoc Source

Arguments

:: JSON a 
=> DB

database

-> Doc

document name

-> (a -> IO a)

update function

-> CouchMonad (Maybe Rev)

If the update succeeds, return the revision number of the result.

getAllDocIds Source

Arguments

:: DB

database name

-> CouchMonad [Doc] 

Views

Creating and querying views

newView Source

Arguments

:: String

database name

-> String

view set name

-> [CouchView]

views

-> CouchMonad () 

queryView Source

Arguments

:: JSON a 
=> DB

database

-> Doc

design

-> Doc

view

-> [(String, JSValue)]

query parameters |Returns a list of rows. Each row is a key, value pair.

-> CouchMonad [(Doc, a)] 

queryViewKeys Source

Arguments

:: DB

database

-> Doc

design

-> Doc

view

-> [(String, JSValue)]

query parameters

-> CouchMonad [Doc] 

Like queryView, but only returns the keys. Use this for key-only views where the value is completely ignored.