putUtf8 method

Future<void> putUtf8(
  1. Pointer<MDB_txn> txn,
  2. String key,
  3. String value, {
  4. String? dbName,
  5. LMDBFlagSet? flags,
})

Stores a UTF-8 encoded string value in the database

The key is used as UTF-8 encoded database key. The value string will be UTF-8 encoded before storage.

The optional dbName parameter specifies a named database. If not provided, the default database will be used.

The optional flags parameter allows setting specific LMDB flags for this operation.

Example:

final txn = await db.txnStart();
try {
  await db.putUtf8(txn, 'user_123', '{"name": "John", "age": 30}');
  await db.txnCommit(txn);
} catch (e) {
  await db.txnAbort(txn);
  rethrow;
}

Throws StateError if the database is closed. Throws LMDBException if the operation fails.

Implementation

Future<void> putUtf8(
  Pointer<MDB_txn> txn,
  String key,
  String value, {
  String? dbName,
  LMDBFlagSet? flags,
}) async {
  await put(txn, key, utf8.encode(value), dbName: dbName, flags: flags);
}