upsertMany method
Upsert items that belong to the given scope
.
Implementation
@override
Future<void> upsertMany(SyncScope scope, List<T> items) async {
if (items.isEmpty) return;
final sk = _scopeKey(scope);
await db.batch((b) {
for (final it in items) {
final idStr = idToString(idOf(it));
b.insert(
db.items,
ItemsCompanion.insert(
scopeName: scope.name,
scopeKeys: sk,
id: idStr,
payload: jsonEncode(toJson(it)),
updatedAt: it.updatedAt.toIso8601String(),
deletedAt: const d.Value.absent(),
),
onConflict: d.DoUpdate(
(old) => ItemsCompanion(
payload: d.Value(jsonEncode(toJson(it))),
updatedAt: d.Value(it.updatedAt.toIso8601String()),
deletedAt: const d.Value(null), // clear tombstone on upsert
),
),
);
}
});
// Enforce cache size limit if configured.
await _maybeEnforceLimit();
}