put method
Future<void>
put(
- String table,
- String key,
- Object? value, {
- bool isDeleted = false,
- CrdtType crdtType = const LwwRegister(),
override
Writes or tombstones the record identified by table/key.
Setting isDeleted to true tombstones the record (soft-delete); the
record remains in the table and is included in changesets so peers can
observe the deletion.
crdtType is the merge rule recorded for this record. It defaults to
LwwRegister (last-write-wins). An engine stores the tag and treats the
value as opaque — the type-aware merge itself happens in TypedCrdtTable,
above this port. An in-memory engine that cannot store the type may ignore
it (typed values are self-describing); a persistent engine must record it.
Implementation
@override
Future<void> put(
String table,
String key,
Object? value, {
bool isDeleted = false,
CrdtType crdtType = const LwwRegister(),
}) async {
_canonical = _canonical.increment();
_open.execute(
'INSERT INTO crdt_records (collection, key, value, is_deleted, hlc, '
'hlc_key, crdt_type) VALUES (?, ?, ?, ?, ?, ?, ?) '
'ON CONFLICT(collection, key) DO UPDATE SET '
'value = excluded.value, is_deleted = excluded.is_deleted, '
'hlc = excluded.hlc, hlc_key = excluded.hlc_key, '
'crdt_type = excluded.crdt_type',
[
table,
key,
jsonEncode(value),
isDeleted ? 1 : 0,
_canonical.toString(),
_hlcKey(_canonical),
crdtType.tag,
],
);
_emit(table);
}