Database.Berkeley.Db
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.
- data DbFlag
- = DB_CREATE
- | DB_DURABLE_UNKNOWN
- | DB_FORCE
- | DB_MULTIVERSION
- | DB_NOMMAP
- | DB_RDONLY
- | DB_RECOVER
- | DB_THREAD
- | DB_TRUNCATE
- | DB_TXN_NOSYNC
- | DB_TXN_NOWAIT
- | DB_TXN_NOT_DURABLE
- | DB_TXN_WRITE_NOSYNC
- | DB_TXN_SYNC
- | DB_TXN_WAIT
- | DB_IGNORE_LEASE
- | DB_AUTO_COMMIT
- | DB_READ_COMMITTED
- | DB_DEGREE_2
- | DB_READ_UNCOMMITTED
- | DB_DIRTY_READ
- | DB_TXN_SNAPSHOT
- | DB_CXX_NO_EXCEPTIONS
- | DB_USE_ENVIRON
- | DB_USE_ENVIRON_ROOT
- | DB_INIT_CDB
- | DB_INIT_LOCK
- | DB_INIT_LOG
- | DB_INIT_MPOOL
- | DB_INIT_REP
- | DB_INIT_TXN
- | DB_LOCKDOWN
- | DB_PRIVATE
- | DB_RECOVER_FATAL
- | DB_REGISTER
- | DB_SYSTEM_MEM
- | DB_EXCL
- | DB_FCNTL_LOCKING
- | DB_NO_AUTO_COMMIT
- | DB_RDWRMASTER
- | DB_WRITEOPEN
- | DB_MULTIPLE
- | DB_MULTIPLE_KEY
- | DB_RMW
- | DB_LOCK_NOWAIT
- | DB_AFTER
- | DB_APPEND
- | DB_BEFORE
- | DB_CONSUME
- | DB_CONSUME_WAIT
- | DB_CURRENT
- | DB_FIRST
- | DB_GET_BOTH
- | DB_GET_BOTHC
- | DB_GET_BOTH_RANGE
- | DB_GET_RECNO
- | DB_JOIN_ITEM
- | DB_KEYFIRST
- | DB_KEYLAST
- | DB_LAST
- | DB_NEXT
- | DB_NEXT_DUP
- | DB_NEXT_NODUP
- | DB_NODUPDATA
- | DB_NOOVERWRITE
- | DB_NOSYNC
- | DB_POSITION
- | DB_PREV
- | DB_PREV_DUP
- | DB_PREV_NODUP
- | DB_SET
- | DB_SET_RANGE
- | DB_SET_RECNO
- | DB_UPDATE_SECONDARY
- | DB_WRITECURSOR
- | DB_WRITELOCK
- data DbError
- = DB_BUFFER_SMALL
- | DB_DONOTINDEX
- | DB_KEYEMPTY
- | DB_KEYEXIST
- | DB_LOCK_DEADLOCK
- | DB_LOCK_NOTGRANTED
- | DB_LOG_BUFFER_FULL
- | DB_NOSERVER
- | DB_NOSERVER_HOME
- | DB_NOSERVER_ID
- | DB_NOTFOUND
- | DB_OLD_VERSION
- | DB_PAGE_NOTFOUND
- | DB_REP_DUPMASTER
- | DB_REP_HANDLE_DEAD
- | DB_REP_HOLDELECTION
- | DB_REP_IGNORE
- | DB_REP_ISPERM
- | DB_REP_JOIN_FAILURE
- | DB_REP_LEASE_EXPIRED
- | DB_REP_LOCKOUT
- | DB_REP_NEWSITE
- | DB_REP_NOTPERM
- | DB_REP_UNAVAIL
- | DB_RUNRECOVERY
- | DB_SECONDARY_BAD
- | DB_VERIFY_BAD
- | DB_VERSION_MISMATCH
- | DB_ACCESSED_DB_ENV_AFTER_CLOSE
- | DB_ACCESSED_DB_AFTER_CLOSE
- | DB_ACCESSED_DB_TXN_AFTER_CLOSE
- | DB_ACCESSED_DB_CURSOR_AFTER_CLOSE
- | SYSTEM_ERROR Int
- data DbException = DbException String DbError
- type DbEnv = ForeignPtr DbEnv_struct
- dbEnv_close :: [DbFlag] -> DbEnv -> IO ()
- data DbEnvCreateFlag
- dbEnv_create :: [DbEnvCreateFlag] -> IO DbEnv
- dbEnv_get_cache_size :: DbEnv -> IO (Int, Int, Int)
- dbEnv_get_lg_regionmax :: DbEnv -> IO Int
- dbEnv_get_lk_max_lockers :: DbEnv -> IO Int
- dbEnv_get_lk_max_locks :: DbEnv -> IO Int
- dbEnv_get_lk_max_objects :: DbEnv -> IO Int
- dbEnv_get_tx_max :: DbEnv -> IO Int
- type DbLock = ForeignPtr DbLock_struct
- data DbLocker
- data DbLockMode
- dbEnv_lock_get :: [DbFlag] -> DbLockMode -> ByteString -> DbEnv -> DbLocker -> IO DbLock
- dbEnv_lock_put :: DbLock -> IO ()
- dbEnv_withLock :: [DbFlag] -> DbLockMode -> ByteString -> DbEnv -> DbLocker -> IO a -> IO a
- dbEnv_open :: [DbFlag] -> Int -> DbEnv -> FilePath -> IO ()
- dbEnv_set_cache_size :: DbEnv -> Int -> Int -> Int -> IO ()
- dbEnv_set_lg_regionmax :: DbEnv -> Int -> IO ()
- data DbLockFlag
- dbEnv_set_lk_detect :: DbEnv -> DbLockFlag -> IO ()
- dbEnv_set_lk_max_lockers :: DbEnv -> Int -> IO ()
- dbEnv_set_lk_max_locks :: DbEnv -> Int -> IO ()
- dbEnv_set_lk_max_objects :: DbEnv -> Int -> IO ()
- dbEnv_set_tx_max :: DbEnv -> Int -> IO ()
- dbEnv_txn_checkpoint :: [DbFlag] -> DbEnv -> Word -> Word -> IO ()
- dbEnv_withTxn :: [DbFlag] -> [DbFlag] -> DbEnv -> Maybe DbTxn -> (DbTxn -> IO a) -> IO a
- dbEnv_txn_begin :: [DbFlag] -> DbEnv -> Maybe DbTxn -> IO DbTxn
- type DbTxn = ForeignPtr DbTxn_struct
- dbTxn_abort :: DbTxn -> IO ()
- dbTxn_commit :: [DbFlag] -> DbTxn -> IO ()
- dbTxn_id :: DbTxn -> IO DbLocker
- type Db = ForeignPtr Db_struct
- db_create :: [DbFlag] -> DbEnv -> IO Db
- db_del :: [DbFlag] -> Db -> Maybe DbTxn -> ByteString -> IO ()
- db_get :: [DbFlag] -> Db -> Maybe DbTxn -> ByteString -> IO (Maybe ByteString)
- data DbType
- = DB_BTREE
- | DB_HASH
- | DB_RECNO
- | DB_QUEUE
- | DB_UNKNOWN
- db_open :: [DbFlag] -> DbType -> Int -> Db -> Maybe DbTxn -> FilePath -> Maybe String -> IO ()
- db_close :: [DbFlag] -> Db -> IO ()
- db_put :: [DbFlag] -> Db -> Maybe DbTxn -> ByteString -> ByteString -> IO ()
- db_set_pagesize :: Db -> Int -> IO ()
- db_withCursor :: [DbFlag] -> Db -> Maybe DbTxn -> (DbCursor -> IO a) -> IO a
- db_cursor :: [DbFlag] -> Db -> Maybe DbTxn -> IO DbCursor
- type DbCursor = ForeignPtr DbCursor_struct
- dbCursor_close :: DbCursor -> IO ()
- dbCursor_count :: [DbFlag] -> DbCursor -> IO Int
- dbCursor_del :: [DbFlag] -> DbCursor -> IO ()
- dbCursor_withCursor :: [DbFlag] -> DbCursor -> (DbCursor -> IO a) -> IO a
- dbCursor_dup :: [DbFlag] -> DbCursor -> IO DbCursor
- dbCursor_get :: [DbFlag] -> DbCursor -> IO (Maybe (ByteString, ByteString))
- dbCursor_set :: [DbFlag] -> DbCursor -> ByteString -> IO (Maybe ByteString)
- dbCursor_put :: [DbFlag] -> DbCursor -> ByteString -> ByteString -> IO ()
- dbToNum :: DbFlag -> CUInt
- dbErrFromNum :: Int -> DbError
- data DbEnv_struct
- data DbTxn_struct
Common
Constructors
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 |
data DbException Source
An exception indicating an error in a Berkeley DB operation.
Constructors
DbException String DbError |
DbEnv
type DbEnv = ForeignPtr DbEnv_structSource
data DbEnvCreateFlag Source
dbEnv_create :: [DbEnvCreateFlag] -> IO DbEnvSource
Create a Berkeley DB environment handle.
dbEnv_get_tx_max :: DbEnv -> IO IntSource
type DbLock = ForeignPtr DbLock_structSource
data DbLockMode Source
Constructors
DB_LOCK_READ | |
DB_LOCK_WRITE | |
DB_LOCK_IWRITE | |
DB_LOCK_IREAD | |
DB_LOCK_IWR |
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.
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.
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
.
data DbLockFlag Source
dbEnv_set_lk_detect :: DbEnv -> DbLockFlag -> IO ()Source
Start the Berkeley DB lock detector.
Checkpoint the transaction subsystem.
DbTxn
Arguments
:: [DbFlag] |
|
-> [DbFlag] |
|
-> 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.
Create a new transaction. You are recommended to use dbEnv_withTxn
instead of this function.
type DbTxn = ForeignPtr DbTxn_structSource
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 -> IO DbLockerSource
Get the locker ID for a transaction, which can be used with dbEnv_withLock
.
Db
type Db = ForeignPtr Db_structSource
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.
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.
Arguments
:: [DbFlag] | |
-> Db | |
-> Maybe DbTxn | |
-> ByteString | Key |
-> ByteString | Value |
-> IO () |
Store the specified value into the database under the specified key.
DbCursor
Arguments
:: [DbFlag] |
|
-> 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.
Arguments
:: [DbFlag] |
|
-> 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
dbErrFromNum :: Int -> DbErrorSource
Needed for BerkeleyDBXML: Convert an error code to a DbError
data DbEnv_struct Source
Needed for BerkeleyDBXML: C pointer type for a DbEnv
data DbTxn_struct Source
Needed for BerkeleyDBXML: C pointer type for a DbTxn