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

InMemoryAdapter()

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_at to the current UTC time. Throws StateError if the row does not exist.
override
deleteMeta(String key) Future<void>
Removes key from _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). Pass includeDeleted: true for 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 null if it does not exist. Soft-deleted rows are returned (inspect deleted_at to detect).
override
getMeta(String key) Future<String?>
Reads the value for key from the engine's _sync_meta KV table, or null if 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 limit rows of table ordered by orderBy (default updated_at), descending by default, continuing after the after cursor.
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 by created_at ASC. 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 = false in insertion order, up to limit.
override
purgeSynced(String table, {DateTime? olderThan, int? keepLatest}) Future<int>
Hard-removes synced rows from table to 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 columns as the schema for table. 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 entryId with payload. 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 key in _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 action inside a single atomic transaction. If action throws, 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 data are written; keys absent from data are unchanged. Caller must include updated_at in data. 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 id exists, otherwise patches the existing row with the keys in data. Soft-delete column on data is honoured (the engine uses upsert to apply pulled tombstones).
override
validateSchema(List<String> tables) Future<void>
Verifies every table in tables includes the required sync columns. Throws SchemaValidationException listing missing columns on mismatch.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited