LMDB class

A high-level Dart interface for LMDB (Lightning Memory-Mapped Database).

LMDB provides a Dart-friendly API for interacting with LMDB, featuring:

  • Automatic transaction management
  • UTF-8 string support
  • Named databases
  • Comprehensive statistics and analysis

Basic usage:

final db = LMDB();

// Initialize the database
await db.init('/path/to/db');

// Store some data
await db.putUtf8Auto('key', 'value');

// Retrieve data
final value = await db.getUtf8Auto('key');
print(value); // Prints: value

// Clean up
db.close();

Advanced usage with explicit transactions:

final db = LMDB();
await db.init('/path/to/db');

final txn = await db.txnStart();
try {
  await db.putUtf8(txn, 'key1', 'value1');
  await db.putUtf8(txn, 'key2', 'value2');
  await db.txnCommit(txn);
} catch (e) {
  await db.txnAbort(txn);
  rethrow;
}

Constructors

LMDB()
Creates a new LMDB instance and loads the native library.

Properties

env → Pointer<MDB_env>
Safe accessor for the environment pointer
no setter
hashCode → int
The hash code for this object.
no setterinherited
isInitialized → bool
Checks if the database has been initialized.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

analyzeUsage() → Future<String>
Analyzes current database usage and returns a formatted report.
close() → void
Closes the database and releases all resources.
cursorClose(Pointer<MDB_cursor> cursor) → void
Closes a cursor
cursorCount(Pointer<MDB_txn> txn, {String? dbName}) → Future<int>
Helper method to count entries using a cursor
cursorDelete(Pointer<MDB_cursor> cursor, [int flags = 0]) → Future<void>
Deletes the entry at current cursor position
cursorGet(Pointer<MDB_cursor> cursor, List<int>? key, CursorOp operation) → Future<CursorEntry?>
Positions cursor and retrieves data
cursorOpen(Pointer<MDB_txn> txn, {String? dbName}) → Future<Pointer<MDB_cursor>>
Opens a new cursor for the specified database
cursorPut(Pointer<MDB_cursor> cursor, List<int> key, List<int> value, int flags) → Future<void>
Stores data at current cursor position
cursorPutUtf8(Pointer<MDB_cursor> cursor, String key, String value, [int flags = 0]) → Future<void>
Convenience method to store UTF-8 strings using cursor
delete(Pointer<MDB_txn> txn, String key, {String? dbName, LMDBFlagSet? flags}) → Future<void>
Deletes a value from the database.
deleteAuto(String key, {String? dbName}) → Future<void>
Deletes a value with automatic transaction management.
dispose() → void
Cleans up resources and closes the database.
get(Pointer<MDB_txn> txn, String key, {String? dbName, LMDBFlagSet? flags}) → Future<List<int>?>
Retrieves a raw byte value from the database.
getAllDatabaseStats() → Future<Map<String, DatabaseStats>>
Gets statistics for all databases in the environment.
getAuto(String key, {String? dbName}) → Future<List<int>?>
Retrieves a raw byte value with automatic transaction management.
getEnvironmentStats() → Future<DatabaseStats>
Gets environment-wide statistics
getErrorString(int err) → String
Gets a human-readable error string for an LMDB error code.
getStats({String? dbName}) → Future<DatabaseStats>
Gets statistics for a database.
getUtf8(Pointer<MDB_txn> txn, String key, {String? dbName}) → Future<String?>
Retrieves a UTF-8 encoded string value from the database
getUtf8Auto(String key, {String? dbName}) → Future<String?>
Retrieves a UTF-8 string with automatic transaction management.
getVersion() → String
Gets the version string of the LMDB library.
init(String dbPath, {LMDBInitConfig? config, LMDBFlagSet? flags}) → Future<void>
Initializes a new LMDB environment at the specified path with optional configuration and flags.
listDatabases() → Future<List<String>>
Lists all named databases in the environment.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(Pointer<MDB_txn> txn, String key, List<int> value, {String? dbName, LMDBFlagSet? flags}) → Future<void>
Stores a raw byte value in the database.
putAuto(String key, List<int> value, {String? dbName, LMDBFlagSet? flags}) → Future<void>
Convenience methods with automatic transaction management Stores a raw byte value with automatic transaction management.
putUtf8(Pointer<MDB_txn> txn, String key, String value, {String? dbName, LMDBFlagSet? flags}) → Future<void>
Stores a UTF-8 encoded string value in the database
putUtf8Auto(String key, String value, {String? dbName, LMDBFlagSet? flags}) → Future<void>
Stores a UTF-8 string with automatic transaction management.
stats(Pointer<MDB_txn> txn, {String? dbName, LMDBFlagSet? flags}) → Future<DatabaseStats>
Gets statistics for a specific database using an explicit transaction.
statsAuto({String? dbName, LMDBFlagSet? flags}) → Future<DatabaseStats>
Gets database statistics with automatic transaction management.
sync(bool force) → Future<void>
Synchronizes the environment to disk.
toString() → String
A string representation of this object.
inherited
txnAbort(Pointer<MDB_txn> txn) → Future<void>
Aborts a transaction and rolls back all its changes.
txnCommit(Pointer<MDB_txn> txn) → Future<void>
Commits a transaction and makes all its changes permanent.
txnStart({Pointer<MDB_txn>? parent, LMDBFlagSet? flags}) → Future<Pointer<MDB_txn>>
Starts a new LMDB transaction.

Operators

operator ==(Object other) → bool
The equality operator.
inherited