liveFields method

  1. @override
Future<Map<String, Object?>> liveFields(
  1. String table,
  2. String prefix
)
override

Returns all live (non-tombstoned) records in table whose key starts with prefix, as a flat map of key → value.

Pass an empty prefix to scan the full table (used by Collection.all and Collection.all). Pass a document-id prefix (e.g. "$id\x1F") to narrow the read to a single document's field records — a disk-backed adapter can use this to avoid loading the whole table.

Implementation

@override
Future<Map<String, Object?>> liveFields(String table, String prefix) async {
  if (_db == null) return {};
  final rows = prefix.isEmpty
      ? _open.select(
          'SELECT key, value FROM crdt_records '
          'WHERE collection = ? AND is_deleted = 0',
          [table],
        )
      : _open.select(
          'SELECT key, value FROM crdt_records '
          'WHERE collection = ? AND is_deleted = 0 '
          'AND substr(key, 1, ?) = ?',
          [table, prefix.length, prefix],
        );
  return {
    for (final r in rows)
      r['key'] as String: jsonDecode(r['value'] as String),
  };
}