BerkeleyDB API
The programming interface of this chicken extension consists of two
modules in a single shared library. You can load the library and
require the main module using
(require-extension berkeley-db)
Serialization Module
In order to be able to store Scheme values inside a BerkeleyDB, the
binding comes with its own serialization facility contained in the
berkeley-db-serialization module. It is not necessary to
interact with this module directly. The module's interface consists of
two simple procedures:
(serialize VALUE [PORT]) => (void)
Serializes a format tag and the given VALUE to the output
PORT (or the current default output port). The serialization
process supports data with shared structure and the external binary
representation does not depend on such things as native byte order.
The following types of Scheme values can be serialized:
* The void value
* The empty list
* Booleans
* Characters
* Numbers, including multiprecision integers, fractions and complex
numbers.
* Symbols
* Strings
* Blobs
* Pairs
* Vectors
* SRFI-4 byte vectors
* SRFI-4 64bit floating point vectors
* SRFI-69 hash tables
* Record instances
(deserialize [PORT]) => VALUE | #!eof
Deserializes a VALUE from the given PORT (or the
current default input port).
If the data read from PORT does not start with the correct
serialization format tag, deserialize instead reads any data
it can get from PORT and returns it as a string.
BerkeleyDB Module
Access to database functionality is provided by the
berkeley-db module.
Database Environments
current-database-environment
A parameter holding the current database environment pointer or
#f.
(open-database-environment
HOME
[#:mode MODE] [#:password PASSWORD]
[#:locking] [#:logging] [#:memory-pool] [#:replication] [#:transactions]
[#:recover] [#:recover/fatal] [#:use-environment] [#:use-environment/root]
[#:create] [#:lockdown] [#:failure-check] [#:private]
[#:auto-commit] [#:direct-i/o] [#:synchronous-i/o] [#:multiversion]
[#:no-mmap] [#:overwrite] [#:initialize-region] [#:timeout->not-granted]
[#:asynchronous] [#:no-wait] [#:snapshot] [#:asynchronous-write]
[#:encrypt/aes])
=>
ENVIRONMENT
Creates a database environment and configures various settings through
setup methods and the open method.
Sets current-database-environment to the newly created
environment.
(close-database-environment [ENVIRONMENT] [#:synchronous]) => (void)
Closes a database environment and destroys the handle. If no
ENVIRONMENT is specified explicitly, closes the current
environment and sets current-database-environment to
#f.
Transactions
(with-transaction
THUNK
[#:read-committed] [#:read-uncommitted] [#:bulk]
[#:asynchronous] [#:no-wait] [#:snapshot] [#:synchronous] [#:wait]
[#:asynchronous-write])
=>
(values ...)
Wraps a call to THUNK in a transaction setup with the
optional flags. Returns whatever (THUNK) returns.
The transaction is committed upon normal return from (THUNK)
and aborted if (THUNK) throws an exception.
Database Files
(copy-database FILE TARGET [#:password PASSWORD] [#:auto-commit]) => (void)
Copies a database from FILE to the TARGET directory.
(rename-database FILE TARGET [DATABASE] [#:auto-commit]) => (void)
Renames a database or database file.
(delete-database FILE [DATABASE] [#:auto-commit]) => (void)
Deletes a database or database file.
Databases
(open-database
FILE [TYPE [DATABASE]]
[#:mode MODE] [#:byte-order BYTE-ORDER] [#:page-size SIZE/BYTES]
[#:heap-max-size SIZE/BYTES] [#:queue-extent-size SIZE/PAGES]
[#:record-size SIZE/BYTES] [#:record-delimiter CHAR] [#:record-padding CHAR]
[#:record-source FILE] [#:password PASSWORD]
[#:auto-commit] [#:create] [#:exclusive] [#:multiversion] [#:no-mmap]
[#:read-only] [#:read-uncommitted] [#:free-threaded] [#:truncate]
[#:checksum] [#:encrypt] [#:transactions-not-durable] [#:duplicates]
[#:duplicates/sorted] [#:no-reverse-splitting] [#:in-order] [#:renumber]
[#:snapshot] [#:encrypt/aes])
=>
DATABASE
Creates a database and configures various settings through setup
methods and the open method.
The TYPE can be b-tree, hash-table,
heap, queue, record-number or
#f. If it is false, the database must exist and its type is
detected automatically.
(database-type DATABASE) => TYPE
Determines the type of a database.
(close-database DATABASE [#:asynchronous]) => (void)
Closes a database and destroys the handle.
(database-associate
DATABASE PROC SECONDARY [FOREIGN]
[#:create] [#:immutable] [#:abort] [#:cascade])
=>
(void)
Associates a database with a secondary index and optionally associates
the secondary index with a foreign key constraint.
(database-ref
DATABASE KEY
[#:consume] [#:consume/wait] [#:ignore-lease]
[#:read-committed] [#:read-uncommitted] [#:read-modify-write])
=>
VALUE
Extracts a record from the database.
(database-set!
DATABASE KEY VALUE
[#:append] [#:no-duplicate] [#:no-overwrite] [#:overwrite-duplicate]
=>
RECNO | (void)
(set! (database-ref DATABASE KEY) VALUE) => (void)
Stores a record in the database. If the #:append mode of
operation is selected, the key of the appended record is returned.
(database-exists?
DATABASE KEY
[#:read-committed] [#:read-uncommitted] [#:read-modify-write])
=>
BOOLEAN
Checks whether a key exists in the database.
(database-delete! DATABASE KEY [#:consume])
Deletes a record from the database.
(database-fold
DATABASE PROC SEED [KEY]
[#:read-committed] [#:read-uncommitted] [#:snapshot])
=>
(PROC KEY VALUE (... (PROC KEY VALUE SEED)))
Folds over the records in the database. If KEY is given, only
fold over the records with matching key.
(database-walk
DATABASE PROC [KEY]
[#:read-committed] [#:read-uncommitted] [#:snapshot])
=>
(void)
Like database-fold, but discarding the result.