lmdb

Documentation
Login

Documentation

LMDB API

(import lmdb)

This CHICKEN binding for LMDB consists of a single module in a shared library of the same name. It offers a simple, hash-table-like programming interface to key value databases stored on disk.

Database Environments

current-database-environment

A parameter holding the current database environment pointer or #f.

(database-environment? OBJECT) ⇒ BOOLEAN

Type predicate for database environments.

(open-database-environment PATH [#:mode MODE] [#:max-databases MAXDBS] [#:max-readers MAXREADERS] [#:max-size MAPSIZE] [#:fixed-map] [#:no-subdirectory] [#:read-only] [#:write-map] [#:no-meta-sync] [#:no-sync] [#:map-async] [#:no-lock] [#:no-read-ahead]) ⇒ ENVIRONMENT

Creates a database environment and configures various settings through setup methods and the open method.

Unless #:no-subdirectory is specified or the given PATH already exists, PATH is created as a directory to contain the database environment.

Sets current-database-environment to the newly created environment.

(close-database-environment [ENVIRONMENT]) ⇒ 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.

(copy-database-environment PATH [ENVIRONMENT] [#:compact]) ⇒ VOID

Copies a database environment to a new PATH, optionally compacting the data. If no ENVIRONMENT is specified explicitly, the current environment is copied.

Transactions

(with-transaction THUNK [ENVIRONMENT] [#:read-only]) ⇒ (values ...)

Wraps a call to THUNK in a transaction. Returns whatever (THUNK) returns. If no ENVIRONMENT is specified explicitly, the current environment is used.

The transaction can optionally be configured as read-only. Read-only transactions may be nested.

All database operations below have to be executed within a transaction.

The transaction is committed upon normal return from (THUNK) and aborted if (THUNK) throws an exception.

(clear-stale-transactions [ENVIRONMENT]) ⇒ INTEGER

Removes stale read-only transactions from the database lockfile (stale read-write transactions are usually removed automatically). If no ENVIRONMENT is specified explicitly, the current environment is used.

The procedure returns the number of stale lock file entries that were removed.

Databases

(database? OBJECT) ⇒ BOOLEAN

Type predicate for databases.

(open-database [NAME] [#:reverse-key] [#:duplicate-sort] [#:integer-key] [#:duplicate-fixed] [#:integer-duplicate] [#:reverse-duplicate] [#:create]) ⇒ DATABASE

Opens a database and configures various flags.

The name of the database can be omitted if the environment was opened without #:max-databases and consists of only a single default database.

If a named database does not exist, #:create must be specified when it is first opened.

(close-database DATABASE [ENVIRONMENT]) ⇒ VOID

Closes a database. If the ENVIRONMENT containing the database is not specified explicitly, the current environment is assumed.

(database-ref DATABASE KEY [DEFAULT]) ⇒ VALUE

Extracts a record with the given KEY from the database. If no record is found and DEFAULT is given, it is invoked in case it is a procedure and returned otherwise. An error is signalled if no record is found and DEFAULT is not given.

Database keys can be strings or blobs. Values extracted from the database are returned as strings.

(database-set! DATABASE KEY VALUE [#:no-duplicate] [#:no-overwrite] [#:append] [#:append/duplicate]) ⇒ VOID (set! (database-ref DATABASE KEY) VALUE) ⇒ VOID

Stores a record in the database with several optional flags modifying the behaviour.

For databases configured with support for multiple values per key, new values are normally added to the set of existing ones. For databases with one value per key, existing records are replaced.

Database keys and values can be strings or blobs.

(database-exists? DATABASE KEY) ⇒ BOOLEAN

Checks whether a key exists in the database.

Database keys can be strings or blobs.

(database-delete! DATABASE KEY [VALUE]) ⇒ VOID

Deletes a record from the database. An error is signalled if no record is found.

For databases configured with support for multiple values per key, the VALUE to delete can be specified explicitly. For databases with one value per key, VALUE is ignored.

Database keys and values can be strings or blobs.

(database-fold PROC SEED DATABASE [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT]) ⇒ (PROC KEY VALUE (... (PROC KEY VALUE SEED)))

Folds over the records in the database. If START is given, only fold over the records with keys greater than or equal to START. If STOP is given, only fold over the records with keys less than (or equal) to STOP. If LIMIT is given, process at most LIMIT records before stopping early.

(database-walk PROC DATABASE [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT]) ⇒ VOID

Like database-fold, but discarding the result.

(database->alist DATABASE [#:from START] [#:to< | #:to<= STOP] [#:limit LIMIT] [#:duplicate-list]) ⇒ ALIST

Convert the records in the database to an association list. If START is given, only list the records with keys greater than or equal to START. If STOP is given, only list the records with keys less than (or equal) to STOP. If LIMIT is given, process at most LIMIT records before stopping early.

Optionally, multiple values for the same key may be folded into lists rather than producing multiple pairs with the same key in the association list.

(alist->database ALIST [NAME] [#:reverse-key] [#:duplicate-sort] [#:integer-key] [#:duplicate-fixed] [#:integer-duplicate] [#:reverse-duplicate] [#:create] [#:no-duplicate] [#:no-overwrite] [#:append] [#:append/duplicate]) ⇒ DATABASE

Convert an association list into records in a database. The procedure accepts the combined flag arguments of open-database and database-set!. The procedure returns a new handle to the database indicated by the given NAME or to the default database.

ALIST must contain pairs of keys and values. Keys can be strings or blobs. Values can be strings, blobs or lists of strings and blobs. If a value is a list, all its elements are inserted into the database with the same key.

If ALIST was generated by database->alist, it is safe to pass #:append or #:append/duplicate to this procedure.