getChangeset method
Future<CrdtChangeset>
getChangeset({
- Map<
String, Query> ? customQueries, - Iterable<
String> ? onlyTables, - String? onlyNodeId,
- String? exceptNodeId,
- Hlc? modifiedOn,
- Hlc? modifiedAfter,
override
Get a Changeset
using the provided changesetQueries
.
Set the filtering parameters to to generate subsets:
onlyTables
only records from the specified tables. Leave empty for all.
onlyNodeId
only records set by the specified node.
exceptNodeId
only records not set by the specified node.
modifiedOn
records whose modified at this exact Hlc.
modifiedAfter
records modified after the specified Hlc.
Implementation
@override
Future<CrdtChangeset> getChangeset({
Map<String, Query>? customQueries,
Iterable<String>? onlyTables,
String? onlyNodeId,
String? exceptNodeId,
Hlc? modifiedOn,
Hlc? modifiedAfter,
}) async {
assert(onlyNodeId == null || exceptNodeId == null);
assert(modifiedOn == null || modifiedAfter == null);
// Modified times use the local node id
modifiedOn = modifiedOn?.apply(nodeId: nodeId);
modifiedAfter = modifiedAfter?.apply(nodeId: nodeId);
var tables = onlyTables ?? await allTables;
if (customQueries != null) {
// Filter out any tables not explicitly mentioned by custom queries
tables = tables.toSet().intersection(customQueries.keys.toSet());
} else {
// Use default changeset queries if none are provided
customQueries = {
for (final table in tables) table: ('SELECT * FROM $table', [])
};
}
return {
for (final table in tables)
table: await _db.query(
SqlUtil.addChangesetClauses(
table,
customQueries[table]!.$1,
onlyNodeId: onlyNodeId,
exceptNodeId: exceptNodeId,
modifiedOn: modifiedOn,
modifiedAfter: modifiedAfter,
),
customQueries[table]!.$2),
};
}