InMemoryLocalAdapter<T extends DatumEntityInterface> class
A complete, dependency-free in-memory LocalAdapter implementation.
Ship-ready for tests, prototypes, and as the reference minimal adapter:
everything is stored in Maps keyed by userId then entity id. It honors
DatumQuery via DatumQueryMatcher, emits real change streams, and provides
transactional backup/rollback — so it advertises WatchableAdapter,
TransactionalAdapter, and PaginatedAdapter.
Subclass it and override individual methods to build a persistent adapter without rewriting the whole 28-method surface — the in-memory behavior acts as a sane default ("Base with defaults").
final adapter = InMemoryLocalAdapter<Task>(fromMap: Task.fromMap);
- Inheritance
-
- Object
- LocalAdapter<
T> - InMemoryLocalAdapter
- Mixed-in types
Constructors
-
InMemoryLocalAdapter({required T fromMap(Map<
String, dynamic> map), int schemaVersion = 0}) -
Creates an in-memory adapter.
fromMapis required so patch and raw-data migration can rebuild entities from maps.
Properties
-
fromMap
→ T Function(Map<
String, dynamic> map) -
Deserializes a stored map back into an entity of type
T.final - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
A descriptive name for the adapter (e.g., "Hive", "SQLite").
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addPendingOperation(
String userId, DatumSyncOperation< T> operation) → Future<void> -
Add a new pending operation to the queue.
override
-
changeStream(
) → Stream< DatumChangeDetail< ?T> > -
Stream of changes that occur in the local storage.
Return null if the adapter doesn't support change notifications.
override
-
checkHealth(
) → Future< AdapterHealthStatus> -
Checks the health of the local adapter.
override
-
clear(
) → Future< void> -
Remove all data from the adapter.
override
-
clearUserData(
String userId) → Future< void> -
Remove all data for a specific user.
override
-
create(
T entity) → Future< void> -
Create a new entity.
override
-
createAll(
List< T> entities) → Future<void> -
Create multiple entities at once.
inherited
-
delete(
String id, {String? userId}) → Future< bool> -
Remove an entity. Returns
trueif an item was deleted.override -
deleteAll(
List< String> ids, {String? userId}) → Future<void> -
Remove multiple entities by their IDs.
inherited
-
dispose(
) → Future< void> -
Dispose of underlying resources (e.g., close database connections).
override
-
fetchRelated<
R extends DatumEntityInterface> (RelationalDatumEntity parent, String relationName, ) → Future< List< R> > -
Fetches related entities based on the relationship definitions from the local source.
inherited
-
getAllRawData(
{String? userId}) → Future< List< Map< >String, dynamic> > -
Fetch all data for a user as a list of raw maps.
This is used during schema migrations to avoid deserialization issues.
override
-
getAllUserIds(
) → Future< List< String> > -
Fetch all unique user IDs that have data stored locally.
override
-
getLastSyncResult(
String userId) → Future< DatumSyncResult< T> ?> -
Retrieves the result of the last synchronization for a user.
override
-
getPendingOperations(
String userId) → Future< List< DatumSyncOperation< >T> > -
Get all pending sync operations.
override
-
getStorageSize(
{String? userId}) → Future< int> -
Returns the storage size in bytes for a given user.
override
-
getStoredSchemaVersion(
) → Future< int> -
Retrieve the schema version stored in the database. Should return 0 if none.
override
-
getSyncMetadata(
String userId) → Future< DatumSyncMetadata?> -
Retrieve metadata about the user's sync state.
override
-
initialize(
) → Future< void> -
Initializes the local storage (e.g., opens databases/boxes).
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
overwriteAllRawData(
List< Map< data, {String? userId}) → Future<String, dynamic> >void> -
Overwrite all existing data with a new set of raw data maps.
This is used during schema migrations after transforming the data.
override
-
patch(
{required String id, required Map< String, dynamic> delta, String? userId}) → Future<T> -
Apply a partial update ("patch") to an existing entity.
override
-
query(
DatumQuery query, {String? userId}) → Future< List< T> > -
Executes a one-time query against the local data source.
override
-
read(
String id, {String? userId}) → Future< T?> -
Fetch a single item by its ID.
override
-
readAll(
{String? userId}) → Future< List< T> > -
Fetch all items.
override
-
readAllPaginated(
PaginationConfig config, {String? userId}) → Future< PaginatedResult< T> > -
Fetch a paginated list of items.
override
-
readByIds(
List< String> ids, {required String userId}) → Future<Map< String, T> > -
Fetch multiple items by their IDs.
override
-
removePendingOperation(
String operationId) → Future< void> -
Remove a pending operation from the queue after it has been synced.
override
-
saveLastSyncResult(
String userId, DatumSyncResult< T> result) → Future<void> -
Saves the result of the last synchronization for a user.
override
-
schemaVersionStream(
) → Stream< int> ? -
A stream that emits when the schema version changes.
inherited
-
setStoredSchemaVersion(
int version) → Future< void> -
Persist the new schema version to the database.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
transaction<
R> (Future< R> action()) → Future<R> -
Executes a block of code within a single atomic transaction.
override
-
update(
T entity) → Future< void> -
Update an existing entity.
override
-
updateAll(
List< T> entities) → Future<void> -
Update multiple entities at once.
inherited
-
updateSyncMetadata(
DatumSyncMetadata metadata, String userId) → Future< void> -
Persist updated sync state metadata.
override
-
watchAll(
{String? userId, bool includeInitialData = true}) → Stream< List< ?T> > -
Watch all items, emitting a new list on any change.
override
-
watchAllPaginated(
PaginationConfig config, {String? userId}) → Stream< PaginatedResult< ?T> > -
Watch a paginated list of items.
Return null if the adapter doesn't support reactive queries.
override
-
watchById(
String id, {String? userId}) → Stream< T?> ? -
Watch a single item by its ID, emitting the item on change or null if deleted.
Return null if the adapter doesn't support reactive queries.
override
-
watchCount(
{DatumQuery? query, String? userId}) → Stream< int> ? -
Watch the total count of entities, optionally matching a query.
Return null if the adapter does not support this feature.
override
-
watchFirst(
{DatumQuery? query, String? userId}) → Stream< T?> ? -
Watch the first entity matching a query, optionally sorted.
Return null if the adapter does not support this feature.
override
-
watchQuery(
DatumQuery query, {String? userId}) → Stream< List< ?T> > -
Watch a subset of items matching a query.
Return null if the adapter doesn't support reactive queries.
override
-
watchRelated<
R extends DatumEntityInterface> (RelationalDatumEntity parent, String relationName, ) → Stream< List< ?R> > -
Reactively watches related entities.
inherited
-
watchStorageSize(
{String? userId}) → Stream< int> -
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited