phoenixdb library

PhoenixDB — an ACID-compliant embedded key/value database for Dart.

The storage engine is written in Rust (B+Tree index, MVCC transactions, write-ahead log, CRC32-checksummed 4 KiB pages) and reached through a zero-overhead dart:ffi binding.

Synchronous use

final db = PhoenixDatabase.open('data.pdb');
db.insert(utf8Key('hello'), utf8Value('world'));
print(db.get(utf8Key('hello')));
db.close();

AsyncPhoenixDB runs every operation on a worker isolate so disk I/O never blocks the UI thread:

final db = await AsyncPhoenixDB.open('data.pdb');
await db.transaction((txn) async {
  await db.insert(utf8Key('a'), utf8Value('1'), txnId: txn);
  await db.insert(utf8Key('b'), utf8Value('2'), txnId: txn);
});
await db.close();

PhoenixDB also ships an embedded k-NN index (HNSW over memory-mapped f32 vectors) for local-first semantic search:

final index = await AsyncPhoenixVectorDB.open('vectors.pvec', dimensions: 384);
await index.insert('doc-1', embedding);
final hits = await index.search(VectorQuery(query, k: 5));
print(hits.first.id);
await index.close();

Limits

Keys are capped at 1 MiB and values at 10 MiB by the FFI layer; the B+Tree additionally caps keys at 1 KiB so a node always holds at least two entries. Values larger than 1 KiB spill onto overflow pages transparently. Vectors are capped at 65 536 dimensions and their ids at 128 bytes.

Classes

AsyncPhoenixDB
Asynchronous PhoenixDB client backed by a dedicated worker isolate.
AsyncPhoenixVectorDB
Asynchronous vector-search client backed by a dedicated worker isolate.
PhoenixDatabase
A synchronous handle to an open PhoenixDB database.
PhoenixPrefs
A typed, async key/value store with a SharedPreferencesAsync-shaped API.
PhoenixStatus
Status codes returned by every phoenix_* entry point.
PhoenixVectorDB
A synchronous handle to an open vector index.
PrefCodec
Encodes and decodes tagged preference values.
SqlResult
The outcome of one SQL statement.
VectorMatch
One search result.
VectorQuery
A k-NN query.
VectorStats
Live, total and deleted record counts.

Enums

PrefType
On-disk type tags. The tag is the first byte of every encoded value.
VectorMetric
Similarity metric used to order neighbours.

Constants

kExpectedAbiVersion → const int
ABI version this Dart package was written against.

Functions

utf8Decode(Uint8List bytes) → String
Decodes UTF-8 bytes back into a string.
utf8Key(String s) → Uint8List
Encodes s as UTF-8 bytes for use as a key.
utf8Value(String s) → Uint8List
Encodes s as UTF-8 bytes for use as a value.

Exceptions / Errors

KeyNotFoundException
Thrown specifically when a key is missing, so callers can catch it narrowly.
PhoenixDecodeException
Thrown when stored bytes cannot be decoded as the type their tag claims.
PhoenixException
Thrown when a native call fails.
PhoenixLoadException
Thrown when the native library cannot be located or is incompatible.
PhoenixTypeMismatch
Thrown when a key is read with an accessor that does not match the type it was written with.