Ensure atomic inside interceptor ? #2853
-
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Jan 22, 2024
Replies: 1 comment 1 reply
-
I haven't tested this, but you can call class _NullUser extends QueryExecutorUser {
@override
Future<void> beforeOpen(QueryExecutor executor, OpeningDetails details) {
throw UnimplementedError();
}
@override
int get schemaVersion => throw UnimplementedError();
} @override
Future<List<Map<String, Object?>>> runSelect(
QueryExecutor executor, String statement, List<Object?> args) async {
if (statements.startsWith('SELECT')) {
return super.runSelect(executor, statement, args);
}
final tx = executor.beginTransaction();
await tx.ensureOpen(_NullUser()); // database connection is already open, so we can use a fake user
// ... prepare logs
await tx.runInsert(log, logArgs);
final result = super.runSelect(tx, statement, args);
await tx.close();
} But if you want to keep a transcript of changes, it might be easier to setup triggers for that. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Ninja4Panda
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I haven't tested this, but you can call
beginTransaction
on the executor to open a transaction executor: