CouchDB-0.8.1.1: 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
data DB
db :: String -> DB
isDBString :: String -> Bool
createDB :: String -> CouchMonad ()
dropDB :: String -> CouchMonad Bool
data Doc
data Rev
doc :: String -> Doc
isDocString :: String -> Bool
newNamedDoc :: JSON a => DB -> Doc -> a -> CouchMonad (Either String Rev)
newDoc :: JSON a => DB -> a -> CouchMonad (Doc, Rev)
updateDoc :: JSON a => DB -> (Doc, Rev) -> a -> CouchMonad (Maybe (Doc, Rev))
deleteDoc :: DB -> (Doc, Rev) -> CouchMonad Bool
forceDeleteDoc :: DB -> Doc -> CouchMonad Bool
getDocPrim :: DB -> Doc -> CouchMonad (Maybe (Doc, Rev, [(String, JSValue)]))
getDoc :: JSON a => DB -> Doc -> CouchMonad (Maybe (Doc, Rev, a))
getAndUpdateDoc :: JSON a => DB -> Doc -> (a -> IO a) -> CouchMonad (Maybe Rev)
getAllDocIds :: DB -> CouchMonad [Doc]
data CouchView
= ViewMap String String
| ViewMapReduce String String String
newView :: String -> String -> [CouchView] -> CouchMonad ()
queryView :: JSON a => DB -> Doc -> Doc -> [(String, JSValue)] -> CouchMonad [(Doc, a)]
queryViewKeys :: DB -> Doc -> Doc -> [(String, JSValue)] -> CouchMonad [Doc]
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
data DB Source
Database name
show/hide Instances
db :: String -> DBSource
Returns a safe database name. Signals an error if the name is invalid.
isDBString :: String -> BoolSource
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
data Doc Source
Document name
show/hide Instances
data Rev Source
Document revision number.
show/hide Instances
doc :: String -> DocSource
Returns a safe document name. Signals an error if the name is invalid.
isDocString :: String -> BoolSource
newNamedDocSource
:: JSON a
=> DBdatabase name
-> Docdocument name
-> adocument body
-> CouchMonad (Either String Rev)Returns Left on a conflict.
newDocSource
:: JSON a
=> DBdatabase name
-> adocument body
-> CouchMonad (Doc, Rev)id and rev of new document
updateDocSource
:: JSON a
=> DBdatabase
-> (Doc, Rev)document and revision
-> anew value
-> CouchMonad (Maybe (Doc, Rev))
deleteDocSource
:: DBdatabase
-> (Doc, Rev)
-> 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 (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
:: JSON a
=> DBdatabase name
-> Docdocument name
-> CouchMonad (Maybe (Doc, Rev, a))Nothing if the doc does not exist
getAndUpdateDocSource
:: JSON a
=> DBdatabase
-> Docdocument name
-> a -> IO aupdate function
-> CouchMonad (Maybe Rev)If the update succeeds, return the revision number of the result.
getAllDocIdsSource
:: DBdatabase name
-> CouchMonad [Doc]
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 [(Doc, a)]
queryViewKeysSource
:: DBdatabase
-> Docdesign
-> Docview
-> [(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.
Produced by Haddock version 2.3.0