Version 0.2: Please note future API-breaking changes are possible!
This module is a direct port of the LMDB API, with the following exceptions:
- The names have been adjusted to Scheme standards. See below.
- All keys and data are passed around as byte strings, not
MDB_vals, or#fin place ofNULL. - All functions that return a status, unless otherwise noted, now throw failures as
exn:mdbstructs. - In the cases where a function takes a single out parameter and returns a status (e.g.
dbi-open,cursor-count), that out parameter is returned instead since failures are thrown. mdb-getreturns the value that was read or#fif it was not found. Any error other thanMDB_NOTFOUNDwill be raised.cursor-gettakes two mutable boxes for the key and data. These boxes will be modified to contain the returned key and data if applicable.#tis returned on success and#fis returned if the status isMDB_NOTFOUND. Any error other thanMDB_NOTFOUNDwill be raised.- Racket booleans are used for the int parameters of
dbi-drop,env-set-flags, andenv-sync. - All the
mdb_env_copy*functions have been condensed down toenv-copy, which takes flags as an optional argument and dispatches to thecopyorcopyfdversion based on the type of the second argument. - Two forms,
with-txnandwith-cursor, are provided to assist with resource management.
As a very direct port, this library gives you plenty of leeway to shoot yourself in the foot.
The names in this library have been updated to fit a bit better into the Racket ecosystem.
Underscores in procedure names have been replaced with dashes and in most places, the MDB_/mdb_ prefix have been stripped off, except where the stripped names wouldn't be informative enough on their own.
Examples:
- The
mdb_env_createprocedure is now justenv-create. - The
MDB_FIRSTcursor op is now just the symbol'FIRST. - The
MDB_DUPSORTdatabase flag is now just the symbol'DUPSORT.
Exceptions:
mdb_drophas been renamed todbi-drop. This aligns it with the otherdbi-procedures and saves us from conflicting with Racket's built-indropthat operates on lists.mdb_versionhas been renamed tomdb-versionso that it doesn't conflict with Racket'sversionfunction.mdb_strerrorhas been renamed tomdb-strerrorbecausestrerroris too general on its own.- All error constants still have the
MDB_prefix.
- Unsupported Features:
- The
MDB_RESERVEandMDB_MULTIPLEwrite flags are not supported. - The following functions have not been exposed:
mdb_env_set_userctxmdb_env_get_userctxmdb_env_set_assertmdb_set_comparemdb_set_dupsortmdb_set_relfuncmdb_set_relctxmdb_cmpmdb_dcmp
- The
- Performance:
- This library copies a lot of memory around when converting to and from byte strings.
- Memory mapping, as used by LMDB, involves cache misses which block the entire OS thread. This means that the entire Racket place can be blocked, since Racket uses green threads. (i.e. Code in another Racket thread can be blocked by LMDB operations if they are in the same place!)
- You'll likely want to open the database with
MDB_NOTLSsince all Racket threads within the same place are run on the same OS thread. If you don't, LMDB will use thread-local storage to track transactions and you won't be able to perform multiple read-only transactions within the same place. - This library does no extra bookkeeping, so as with regular LMDB, it's up to you to clean up what you create, be they environments, transactions, or cursors.
The
with-txnandwith-cursorforms can assist in cases.
This package bundles LMDB dynamic libraries for various platforms which were sourced from these locations:
- Windows 64-bit: https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-lmdb-0.9.29-1-any.pkg.tar.zst (MSYS2)
- Linux 64-bit: https://mirror.pkgbuild.com/extra/os/x86_64/lmdb-0.9.29-1-x86_64.pkg.tar.zst (Arch Linux)
LMDB is released under the OpenLDAP license. The wrapper itself is licensed under the MIT license.