InMemoryAdapter class
An in-memory LocalDatabaseAdapter for tests and the contract suite.
Published via package:flutter_universal_sync_core/testing.dart so
downstream packages (e.g. the sync engine) can wire it into their own
test suites without re-implementing a local store.
Storage shape:
_tables: tableName -> rowId -> row map
_schemas: tableName -> set of column names (registered via
registerTable in tests before validateSchema is called)
_queue: insertion-ordered list of queue entries
_meta: engine _sync_meta key/value store
- Implemented types
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> -
Releases underlying resources. Safe to call multiple times.
override
-
delete(
String table, String id) → Future< void> -
Soft-deletes the row: sets
deleted_atto the current UTC time. Throws StateError if the row does not exist.override -
deleteMeta(
String key) → Future< void> -
Removes
keyfrom_sync_meta. No-op if the key does not exist. Atomic with respect to transaction. Added in 0.2.0.override -
enqueueSync(
SyncQueueEntry entry) → Future< void> -
Appends a queue entry. Should only be invoked inside transaction
alongside the corresponding domain-table mutation.
override
-
getAll(
String table, {bool includeDeleted = false}) → Future< List< Map< >String, dynamic> > -
Returns all rows from
table. Default behaviour filters out soft-deleted rows (deleted_at IS NULL). PassincludeDeleted: truefor a full listing (e.g. for the sync engine's pull-reconciliation).override -
getById(
String table, String id) → Future< Map< String, dynamic> ?> -
Returns the row with the given id, or
nullif it does not exist. Soft-deleted rows are returned (inspectdeleted_atto detect).override -
getMeta(
String key) → Future< String?> -
Reads the value for
keyfrom the engine's_sync_metaKV table, ornullif the key does not exist. Added in 0.2.0.override -
getPage(
String table, {int limit = 20, String orderBy = SyncColumns.updatedAt, bool descending = true, PageCursor? after, bool includeDeleted = false}) → Future< PageResult> -
Returns up to
limitrows oftableordered byorderBy(defaultupdated_at),descendingby default, continuing after theaftercursor.override -
init(
) → Future< void> -
Opens the underlying database. Must be called exactly once.
override
-
insert(
String table, Map< String, dynamic> data) → Future<void> -
Inserts a row. Throws StateError if a row with the same id exists.
Caller supplies all sync metadata fields; the adapter does not
populate them.
override
-
markSynced(
String queueEntryId) → Future< void> -
Marks the given queue entry as successfully synced.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pendingForEntity(
String table, String entityId) → Future< List< SyncQueueEntry> > -
Returns unsynced queue entries for the row identified by
(
table,entityId), ordered bycreated_atASC. Used by the engine's pull pipeline to detect pending local edits that conflict with an incoming remote row. Added in 0.2.0.override -
pendingSyncEntries(
{int? limit, DateTime? readyAt}) → Future< List< SyncQueueEntry> > -
Returns entries with
synced = falsein insertion order, up tolimit.override -
purgeSynced(
String table, {DateTime? olderThan, int? keepLatest}) → Future< int> -
Hard-removes synced rows from
tableto bound the local cache, returning the number removed.override -
recordSyncFailure(
String queueEntryId, String error, {DateTime? nextRetryAt, bool incrementRetryCount = true}) → Future< void> -
Records a failed push attempt for
queueEntryId.override -
registerTable(
String table, Iterable< String> columns) → void -
Registers
columnsas the schema fortable. Tests call this before validateSchema to simulate user-declared tables. -
rewriteQueuePayload(
String entryId, Map< String, dynamic> payload) → Future<void> -
Replaces the payload of the queue entry
entryIdwithpayload. Other fields (retry_count, last_error, operation, created_at, next_retry_at, synced) are untouched. Throws StateError if no such entry exists. Atomic with transaction. Added in 0.2.0.override -
setMeta(
String key, String value) → Future< void> -
Inserts or replaces the value for
keyin_sync_meta. Atomic with respect to transaction; rolled back on throw. Added in 0.2.0.override -
toString(
) → String -
A string representation of this object.
inherited
-
transaction<
T> (Future< T> action()) → Future<T> -
Runs
actioninside a single atomic transaction. Ifactionthrows, every write performed during the callback is rolled back.override -
update(
String table, String id, Map< String, dynamic> data) → Future<void> -
Patches the row with matching id — keys in
dataare written; keys absent fromdataare unchanged. Caller must includeupdated_atindata. Throws StateError if the row does not exist.override -
upsert(
String table, Map< String, dynamic> data) → Future<void> -
Inserts the row if no row with the same
idexists, otherwise patches the existing row with the keys indata. Soft-delete column ondatais honoured (the engine uses upsert to apply pulled tombstones).override -
validateSchema(
List< String> tables) → Future<void> -
Verifies every table in
tablesincludes the required sync columns. Throws SchemaValidationException listing missing columns on mismatch.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited