apply method
Implementation
@override
Future<DVRemoteOutcome> apply(DVMutation mutation) async {
await _ensureOnce();
final List<Map<String, Object?>> seen = await _database.query(
'SELECT outcome FROM $appliedTable WHERE mutation_id = ?',
<Object?>[mutation.mutationId],
);
if (seen.isNotEmpty) {
final Map<String, Object?> outcome =
jsonDecode('${seen.first['outcome']}') as Map<String, Object?>;
final Object? rejection = outcome['rejection'];
if (rejection is String) return DVRemoteOutcome.rejected(rejection);
return DVRemoteOutcome.applied(await table.read(mutation.key),
discarded: outcome['discarded'] == true);
}
final DVRemoteOutcome outcome = await _applyOnce(mutation);
await _database.execute(
'INSERT INTO $appliedTable (mutation_id, outcome) VALUES (?, ?)',
<Object?>[
mutation.mutationId,
jsonEncode(<String, Object?>{
'discarded': outcome.discarded,
if (outcome.rejection != null) 'rejection': outcome.rejection,
}),
],
);
return outcome;
}