CouchDB-1.2.3: CouchDB interface

Safe HaskellNone
LanguageHaskell2010

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.

Instances
Monad CouchMonad Source # 
Instance details

Defined in Database.CouchDB.HTTP

Methods

(>>=) :: CouchMonad a -> (a -> CouchMonad b) -> CouchMonad b #

(>>) :: CouchMonad a -> CouchMonad b -> CouchMonad b #

return :: a -> CouchMonad a #

fail :: String -> CouchMonad a #

Functor CouchMonad Source # 
Instance details

Defined in Database.CouchDB.HTTP

Methods

fmap :: (a -> b) -> CouchMonad a -> CouchMonad b #

(<$) :: a -> CouchMonad b -> CouchMonad a #

Applicative CouchMonad Source # 
Instance details

Defined in Database.CouchDB.HTTP

Methods

pure :: a -> CouchMonad a #

(<*>) :: CouchMonad (a -> b) -> CouchMonad a -> CouchMonad b #

liftA2 :: (a -> b -> c) -> CouchMonad a -> CouchMonad b -> CouchMonad c #

(*>) :: CouchMonad a -> CouchMonad b -> CouchMonad b #

(<*) :: CouchMonad a -> CouchMonad b -> CouchMonad a #

MonadIO CouchMonad Source # 
Instance details

Defined in Database.CouchDB.HTTP

Methods

liftIO :: IO a -> CouchMonad a #

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
Show DB Source # 
Instance details

Defined in Database.CouchDB

Methods

showsPrec :: Int -> DB -> ShowS #

show :: DB -> String #

showList :: [DB] -> ShowS #

JSON DB Source # 
Instance details

Defined in Database.CouchDB

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

Instances
Eq Doc Source # 
Instance details

Defined in Database.CouchDB

Methods

(==) :: Doc -> Doc -> Bool #

(/=) :: Doc -> Doc -> Bool #

Ord Doc Source # 
Instance details

Defined in Database.CouchDB

Methods

compare :: Doc -> Doc -> Ordering #

(<) :: Doc -> Doc -> Bool #

(<=) :: Doc -> Doc -> Bool #

(>) :: Doc -> Doc -> Bool #

(>=) :: Doc -> Doc -> Bool #

max :: Doc -> Doc -> Doc #

min :: Doc -> Doc -> Doc #

Read Doc Source # 
Instance details

Defined in Database.CouchDB

Show Doc Source # 
Instance details

Defined in Database.CouchDB

Methods

showsPrec :: Int -> Doc -> ShowS #

show :: Doc -> String #

showList :: [Doc] -> ShowS #

JSON Doc Source # 
Instance details

Defined in Database.CouchDB

data Rev Source #

Document revision number.

Instances
Eq Rev Source # 
Instance details

Defined in Database.CouchDB

Methods

(==) :: Rev -> Rev -> Bool #

(/=) :: Rev -> Rev -> Bool #

Ord Rev Source # 
Instance details

Defined in Database.CouchDB

Methods

compare :: Rev -> Rev -> Ordering #

(<) :: Rev -> Rev -> Bool #

(<=) :: Rev -> Rev -> Bool #

(>) :: Rev -> Rev -> Bool #

(>=) :: Rev -> Rev -> Bool #

max :: Rev -> Rev -> Rev #

min :: Rev -> Rev -> Rev #

Show Rev Source # 
Instance details

Defined in Database.CouchDB

Methods

showsPrec :: Int -> Rev -> ShowS #

show :: Rev -> String #

showList :: [Rev] -> ShowS #

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.