CouchDB-0.10.1: CouchDB interface

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.

runCouchDBSource

Arguments

:: String

hostname

-> Int

port

-> CouchMonad a 
-> IO a 

runCouchDB' :: CouchMonad a -> IO aSource

Connects to the CouchDB server at localhost:5984.

Explicit Connections

data CouchConn Source

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

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

Run a CouchDB computation with an existing CouchDB connection.

createCouchConnSource

Arguments

:: String

hostname

-> Int

port

-> IO CouchConn 

Create a CouchDB connection for use with runCouchDBWith.

closeCouchConn :: CouchConn -> IO ()Source

Closes an open CouchDB connection

Databases

data DB Source

Database name

Instances

db :: String -> DBSource

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.

dropDBSource

Arguments

:: String 
-> CouchMonad Bool

False if the database does not exist

Documents

data Doc Source

Document name

Instances

data Rev Source

Document revision number.

Instances

doc :: String -> DocSource

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

rev :: String -> RevSource

Returns a Rev

newNamedDocSource

Arguments

:: JSON a 
=> DB

database name

-> Doc

document name

-> a

document body

-> CouchMonad (Either String Rev)

Returns Left on a conflict.

newDocSource

Arguments

:: JSON a 
=> DB

database name

-> a

document body

-> CouchMonad (Doc, Rev)

id and rev of new document

updateDocSource

Arguments

:: JSON a 
=> DB

database

-> (Doc, Rev)

document and revision

-> a

new value

-> CouchMonad (Maybe (Doc, Rev)) 

deleteDocSource

Arguments

:: DB

database

-> (Doc, Rev) 
-> CouchMonad Bool 

forceDeleteDocSource

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.

getDocPrimSource

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.

getDocSource

Arguments

:: JSON a 
=> DB

database name

-> Doc

document name

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

Nothing if the doc does not exist

getAllDocsSource

Arguments

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

query parameters

-> CouchMonad [(Doc, a)] 

getAndUpdateDocSource

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.

getAllDocIdsSource

Arguments

:: DB

database name

-> CouchMonad [Doc] 

Views

Creating and querying views

newViewSource

Arguments

:: String

database name

-> String

view set name

-> [CouchView]

views

-> CouchMonad () 

queryViewSource

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)] 

queryViewKeysSource

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.