BerkeleyDB-0.8: Berkeley DB binding

Database.Berkeley.Db

Contents

Description

Berkeley DB binding. All IO monad functions can throw DbException.

This documentation is not a complete description of the Berkeley DB interface. You will need to refer to Berkeley DB's C or C++ API documentation for the details.

Synopsis

Common

data DbError Source

Constructors

DB_BUFFER_SMALL

User memory too small for return.

DB_DONOTINDEX

"Null" return from 2ndary callbk.

DB_KEYEMPTY

Key/data deleted or never created.

DB_KEYEXIST

The key/data pair already exists.

DB_LOCK_DEADLOCK

Deadlock.

DB_LOCK_NOTGRANTED

Lock unavailable.

DB_LOG_BUFFER_FULL

In-memory log buffer full.

DB_NOSERVER

Server panic return.

DB_NOSERVER_HOME

Bad home sent to server.

DB_NOSERVER_ID

Bad ID sent to server.

DB_NOTFOUND

Key/data pair not found (EOF).

DB_OLD_VERSION

Out-of-date version.

DB_PAGE_NOTFOUND

Requested page not found.

DB_REP_DUPMASTER

There are two masters.

DB_REP_HANDLE_DEAD

Rolled back a commit.

DB_REP_HOLDELECTION

Time to hold an election.

DB_REP_IGNORE

This msg should be ignored.

DB_REP_ISPERM

Cached not written perm written.

DB_REP_JOIN_FAILURE

Unable to join replication group.

DB_REP_LEASE_EXPIRED

Master lease has expired.

DB_REP_LOCKOUT

API/Replication lockout now.

DB_REP_NEWSITE

New site entered system.

DB_REP_NOTPERM

Permanent log record not written.

DB_REP_UNAVAIL

Site cannot currently be reached.

DB_RUNRECOVERY

Panic return.

DB_SECONDARY_BAD

Secondary index corrupt.

DB_VERIFY_BAD

Verify failed; bad format.

DB_VERSION_MISMATCH

Environment version mismatch.

DB_ACCESSED_DB_ENV_AFTER_CLOSE

Haskell binding: Attempted to use a DbEnv handle after it was closed

DB_ACCESSED_DB_AFTER_CLOSE

Haskell binding: Attempted to use a Db handle after it was closed

DB_ACCESSED_DB_TXN_AFTER_CLOSE

Haskell binding: Attempted to use a DbTxn handle after it was closed

DB_ACCESSED_DB_CURSOR_AFTER_CLOSE

Haskell binding: Attempted to use a DbCursor handle after it was closed

SYSTEM_ERROR Int

An errno value returned by the operating system

Instances

data DbException Source

An exception indicating an error in a Berkeley DB operation.

Constructors

DbException String DbError 

DbEnv

dbEnv_close :: [DbFlag] -> DbEnv -> IO ()Source

Close the Berkeley DB environment.

dbEnv_create :: [DbEnvCreateFlag] -> IO DbEnvSource

Create a Berkeley DB environment handle.

type DbLock = ForeignPtr DbLock_structSource

dbEnv_lock_getSource

Arguments

:: [DbFlag] 
-> DbLockMode 
-> ByteString

Object, which is a key that identifies this lock

-> DbEnv 
-> DbLocker

The identity of the locker.

-> IO DbLock 

Acquire a DbLock. dbTxn_id converts a DbTxn to a DbLocker.

dbEnv_lock_put :: DbLock -> IO ()Source

Release a DbLock acquired by dbEnv_lock_get.

dbEnv_withLockSource

Arguments

:: [DbFlag] 
-> DbLockMode 
-> ByteString

Object, which is an environment-wide key that identifies this lock

-> DbEnv 
-> DbLocker

The identity of the locker.

-> IO a

Computation to perform under lock

-> IO a 

Wrap dbEnv_lock_get / dbEnv_lock_put around the specified computation. dbTxn_id converts a DbTxn to a DbLocker.

dbEnv_openSource

Arguments

:: [DbFlag] 
-> Int

UNIX file creation mode, or 0, meaning "readable and writable by both owner and group"

-> DbEnv 
-> FilePath

Database environment's home directory

-> IO () 

Open the Berkeley DB environment, which must be done before db_open.

dbEnv_set_lk_detect :: DbEnv -> DbLockFlag -> IO ()Source

Start the Berkeley DB lock detector.

dbEnv_txn_checkpointSource

Arguments

:: [DbFlag] 
-> DbEnv 
-> Word

kbyte

-> Word

minutes

-> IO () 

Checkpoint the transaction subsystem.

DbTxn

dbEnv_withTxnSource

Arguments

:: [DbFlag]

dbEnv_txn_begin flags

-> [DbFlag]

dbTxn_commit flags

-> DbEnv 
-> Maybe DbTxn

Parent transaction

-> (DbTxn -> IO a)

The action to run inside a transaction

-> IO a 

An exception-safe helper that runs an action inside a transaction. It will commit on completion, or abort if an exception is thrown.

dbEnv_txn_beginSource

Arguments

:: [DbFlag] 
-> DbEnv 
-> Maybe DbTxn

Optional parent transaction

-> IO DbTxn 

Create a new transaction. You are recommended to use dbEnv_withTxn instead of this function.

dbTxn_abort :: DbTxn -> IO ()Source

Abort a transaction, rolling back any writes that were made. You are recommended to use dbEnv_withTxn instead of this function.

dbTxn_commit :: [DbFlag] -> DbTxn -> IO ()Source

Commit a transaction. You are recommended to use dbEnv_withTxn instead of this function.

dbTxn_id :: DbTxn -> DbLockerSource

Get the locker ID for a transaction, which can be used with dbEnv_withLock.

Db

type Db = ForeignPtr Db_structSource

db_create :: [DbFlag] -> DbEnv -> IO DbSource

Create a database handle.

db_getSource

Arguments

:: [DbFlag] 
-> Db 
-> Maybe DbTxn 
-> ByteString

Key

-> IO (Maybe ByteString) 

Look the key up in the database, and return Just the stored value, or Nothing if it was not found.

db_openSource

Arguments

:: [DbFlag] 
-> DbType 
-> Int

Unix file creation mode, or 0, meaning "readable and writable by both owner and group"

-> Db 
-> Maybe DbTxn 
-> FilePath

Filename

-> Maybe String

Optional name of database within the file

-> IO () 

Open a database.

db_putSource

Arguments

:: [DbFlag] 
-> Db 
-> Maybe DbTxn 
-> ByteString

Key

-> ByteString

Value

-> IO () 

Store the specified value into the database under the specified key.

DbCursor

db_withCursorSource

Arguments

:: [DbFlag]

db_cursor flags

-> Db 
-> Maybe DbTxn

Optional tansaction

-> (DbCursor -> IO a)

The action that operates on the cursor

-> IO a 

An exception-safe helper that creates a cursor, passes it to an action, and cleans up afterwards.

db_cursor :: [DbFlag] -> Db -> Maybe DbTxn -> IO DbCursorSource

Open a DbCursor. You are recommended to use db_withCursor instead of this function.

type DbCursor = ForeignPtr DbCursor_structSource

dbCursor_close :: DbCursor -> IO ()Source

Close a DBCursor. You are recommended to use db_withCursor instead of this function.

dbCursor_count :: [DbFlag] -> DbCursor -> IO IntSource

Count the number of duplicates at the cursor position.

dbCursor_del :: [DbFlag] -> DbCursor -> IO ()Source

Delete the record at the cursor position.

dbCursor_withCursorSource

Arguments

:: [DbFlag]

db_cursor flags

-> DbCursor

The source cursor

-> (DbCursor -> IO a)

The action that operates on the cursor

-> IO a 

An exception-safe helper that duplicates a cursor using dbCursor_dup, passes it to an action, and cleans up afterwards.

dbCursor_dup :: [DbFlag] -> DbCursor -> IO DbCursorSource

Create a duplicate of the specified cursor.

dbCursor_get :: [DbFlag] -> DbCursor -> IO (Maybe (ByteString, ByteString))Source

Fetch the record pointed at by the cursor (modified by the flags - see the Berkeley DB documentation), and return Just the (key, value) pair at the cursor position, or Nothing if no record was found.

dbCursor_set :: [DbFlag] -> DbCursor -> ByteString -> IO (Maybe ByteString)Source

Move the cursor to the specified key/data pair of the database, and return the datum associated with the given key, or Nothing if it wasn't matched. (This is DBC->get with the DB_SET flag. The DB_SET flag is implied.)

dbCursor_put :: [DbFlag] -> DbCursor -> ByteString -> ByteString -> IO ()Source

stores key/data pairs into the database in the context of the cursor.

Private

Needed for BerkeleyDBXML: Binary representation of a DbFlag

Needed for BerkeleyDBXML: Convert an error code to a DbError

Needed for BerkeleyDBXML: C pointer type for a DbEnv

Needed for BerkeleyDBXML: C pointer type for a DbTxn