sembast library

sembast, a NoSQL document database for Dart and Flutter.

This library holds the API used on every platform: StoreRef (a store of records, like a table or a collection), RecordRef (one record), Finder and Filter (queries), Database and Transaction.

A database is opened with a DatabaseFactory, which depends on the platform:

  • databaseFactoryIo from package:sembast/sembast_io.dart: Dart VM and Flutter Android, iOS, macOS, Windows and Linux. One file per database.
  • databaseFactoryWeb from package:sembast_web/sembast_web.dart: web and Flutter web (IndexedDB).
  • newDatabaseFactoryMemory() from package:sembast/sembast_memory.dart: unit tests, nothing is saved.
import 'package:sembast/sembast_io.dart';

Future<void> main() async {
  // Open the database once and keep it for the lifetime of the app.
  var db = await databaseFactoryIo.openDatabase('my_app.db');
  var store = intMapStoreFactory.store('animals');
  var key = await store.add(db, {'name': 'cat'});
  print(await store.record(key).get(db)); // {name: cat}
  await db.close();
}

Every read and write takes the Database (or the Transaction inside db.transaction) as its first argument. The 1.x API (db.put(value, key), db.getStore(name), the Store and Record classes) no longer exists, see https://github.com/tekartik/sembast.dart/blob/master/sembast/doc/new_api.md

Classes

AsyncContentCodecBase
Base class for a custion implementation, by defining only decodeAsync and encodeAsync
Boundary
Sort order boundary, lower or upper to use in a Finder
Database
Database.
DatabaseClient
Database client (either Database or Transaction)
DatabaseFactory
The database factory that allow opening database
DatabaseMode
The modes in which a Database can be opened.
Field
Special field access
FieldKey
Field Key utilities
FieldValue
Update values
Filter
Filter for searching into the database
Finder
Finder helper for searching a given store
QueryRef<K extends Key?, V extends Value?>
A query on a store.
RecordChange<K, V>
Record change info streamed during StoreRef.onChange.
RecordRef<K extends Key?, V extends Value?>
An immutable record reference
RecordSnapshot<K extends Key?, V extends Value?>
A read record
RecordsRef<K extends Key?, V extends Value?>
An immutable reference to multiple records
SembastCodec
The sembast codec to use to read/write records.
SortOrder<T extends Object?>
Sort order
StoreFactory<K extends Key?, V extends Value?>
Store factory interface
StoreRef<K extends Key?, V extends Value?>
A pointer to a store.
Transaction
Database transaction.

Extensions

DatabaseExtension on Database
Database extension methods.
RecordSnapshotIterableExtension on Iterable<RecordSnapshot<K, V>>
Extension on iterable of record snapshot
SembastDatabaseAllStoresChangesListenerExtension on Database
All stores changes listener extension.
SembastDatabaseClientExtension on DatabaseClient
Database client extension methods.
SembastDatabaseFactorySandboxExtension on DatabaseFactory
Database factory sandbox extension.
SembastFilterCombination on Filter
Provides convenience methods for combining multiple Filters.
SembastQueryRefCommonExtension on QueryRef<K, V>
Common extension
SembastQueryRefExtension on QueryRef<K, V>
Query db actions.
SembastQueryRefSyncExtension on QueryRef<K, V>
Query db actions. synchronous access.
SembastRecordChangeExtension on RecordChange<K, V>
Record change helper.
SembastRecordRefExtension on RecordRef<K, V>
Record ref sembast public extension.
SembastRecordRefSyncExtension on RecordRef<K, V>
Record ref sembast public extension.
SembastRecordsRefCommonExtension on RecordsRef<K, V>
Record ref common extension.
SembastRecordsRefExtension on RecordsRef<K, V>
Record ref sembast public extension.
SembastRecordsRefSyncExtension on RecordsRef<K, V>
Record ref sembast public extension.
SembastStoreRefCommonExtension on StoreRef<K, V>
Store ref common public sembast extension (no db access).
SembastStoreRefExtension on StoreRef<K, V>
Store ref public sembast extension.
SembastStoreRefSyncExtension on StoreRef<K, V>
Store ref public sembast extension.

Properties

debugSembastWarnDatabaseCallInTransaction ↔ bool
Warning when using database object in transaction in debug mode could become the default one day
getter/setter pair
intMapStoreFactory → StoreFactoryBase<int, Map<String, Object?>>
Store factory with key as int and value as Map
final
sembastCodecDefault ↔ SembastCodec
Json Codec with supports for DateTime and Blobs (UInt8List)
getter/setter pair
sembastDefaultTypeAdapters → List<SembastTypeAdapter<Object, String>>
Support Timestamp and Blob
final
stringMapStoreFactory → StoreFactoryBase<String, Map<String, Object?>>
Store factory with key as String and value as Map
final

Functions

disableSembastCooperator() → void
Disable sembast cooperator.
enableSembastCooperator({int? delayMicroseconds, int? pauseMicroseconds}) → void
Re-enable sembast cooperator or change default pause and delay
sembastCodecWithAdapters(Iterable<SembastTypeAdapter> adapters) → SembastCodec
Default codec has no toString converted and no signature. as format is expected to be compatible

Typedefs

OnVersionChangedFunction = FutureOr Function(Database db, int oldVersion, int newVersion)
Callback interface called when the existing version differs from the one expected.
RecordKeyBase = Object
Base key.
RecordValueBase = Object
Base value.
SembastTransactionFunction<T> = FutureOr<T> Function(Transaction transaction)
Transaction function.
StoresTrackOnChangesStorePredicate = bool Function(String store)
Check whether a store should track changes by default store ending with _local are excluded
TransactionRecordChangeListener<K, V> = FutureOr<void> Function(Transaction transaction, List<RecordChange<K, V>> changes)
Record change listener

Exceptions / Errors

DatabaseException
Database exception.