CouchDB-0.8.0.3: CouchDB interfaceSource codeContentsIndex
Database.CouchDB
Contents
Initialization
Databases
Documents
Views
Description
Interface to CouchDB.
Synopsis
data CouchMonad a
runCouchDB :: String -> Int -> CouchMonad a -> IO a
runCouchDB' :: CouchMonad a -> IO a
createDB :: String -> CouchMonad ()
dropDB :: String -> CouchMonad Bool
newNamedDoc :: JSON a => DB -> Doc -> a -> CouchMonad (Either String String)
newDoc :: JSON a => DB -> a -> CouchMonad (JSString, JSString)
updateDoc :: JSON a => DB -> (JSString, JSString) -> a -> CouchMonad (Maybe (JSString, JSString))
deleteDoc :: DB -> (JSString, JSString) -> CouchMonad Bool
forceDeleteDoc :: DB -> Doc -> CouchMonad Bool
getDocPrim :: DB -> Doc -> CouchMonad (Maybe (JSString, JSString, [(String, JSValue)]))
getDoc :: JSON a => DB -> Doc -> CouchMonad (Maybe (JSString, JSString, a))
getAndUpdateDoc :: JSON a => DB -> Doc -> (a -> a) -> CouchMonad (Maybe String)
getAllDocIds :: DB -> CouchMonad [String]
data CouchView
= ViewMap String String
| ViewMapReduce String String String
newView :: String -> String -> [CouchView] -> CouchMonad ()
queryView :: JSON a => DB -> Doc -> Doc -> [(String, JSValue)] -> CouchMonad [(JSString, a)]
queryViewKeys :: DB -> Doc -> Doc -> [(String, JSValue)] -> CouchMonad [String]
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.
show/hide Instances
runCouchDBSource
::
=> Stringhostname
-> Intport
-> CouchMonad a
-> IO a
runCouchDB' :: CouchMonad a -> IO aSource
Connects to the CouchDB server at localhost:5984.
Databases
createDB :: String -> CouchMonad ()Source
Creates a new database. Throws an exception if the database already exists.
dropDBSource
:: String
-> CouchMonad BoolFalse if the database does not exist
Documents
newNamedDocSource
:: JSON a
=> DBdatabase name
-> Docdocument name
-> adocument body
-> CouchMonad (Either String String)Returns Left on a conflict. Returns Right with the revision number on success.
newDocSource
:: JSON a
=> DBdatabase name
-> adocument body
-> CouchMonad (JSString, JSString)id and rev of new document
updateDocSource
:: JSON a
=> DBdatabase
-> (JSString, JSString)document and revision
-> anew value
-> CouchMonad (Maybe (JSString, JSString))
deleteDocSource
:: DBdatabase
-> (JSString, JSString)document and revision
-> CouchMonad Bool
forceDeleteDocSource
:: DBdatabase
-> Docdocument 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
:: DBdatabase name
-> Docdocument name
-> CouchMonad (Maybe (JSString, JSString, [(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
:: JSON a
=> DBdatabase name
-> Docdocument name
-> CouchMonad (Maybe (JSString, JSString, a))Nothing if the doc does not exist
getAndUpdateDocSource
:: JSON a
=> DBdatabase
-> Docdocument name
-> a -> aupdate function
-> CouchMonad (Maybe String)If the update succeeds, return the revision number of the result.
getAllDocIdsSource
:: DBdatabase name
-> CouchMonad [String]
Views
Creating and querying views
data CouchView Source
Constructors
ViewMap String String
ViewMapReduce String String String
newViewSource
:: Stringdatabase name
-> Stringview set name
-> [CouchView]views
-> CouchMonad ()
queryViewSource
:: JSON a
=> DBdatabase
-> Docdesign
-> Docview
-> [(String, JSValue)]query parameters |Returns a list of rows. Each row is a key, value pair.
-> CouchMonad [(JSString, a)]
queryViewKeysSource
:: DBdatabase
-> Docdesign
-> Docview
-> [(String, JSValue)]query parameters
-> CouchMonad [String]
Like queryView, but only returns the keys. Use this for key-only views where the value is completely ignored.
Produced by Haddock version 2.3.0