-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fine-grained query intercepting #3404
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! The approach looks ok as an easy way to only apply the interceptor in some scopes.
We'll also need an test for this (see interceptor_test.dart
as an example), something that applies an interceptor for a transaction and asserts that it was applied for the methods within the transaction block.
How about an approach that allows applying a await database.withInterceptor(interceptor: yourInterceptor, () async {
// In this block, the interceptor is active
await database.transaction(() async {
// intercepted beginTransaction(), and so on...
});
}); This has the advantage that it doesn't just apply to transactions, but may also be used for batches or any other drift APIs. Whenever some specific operation should run with an interceptor, you'd just use that method. It also gives you control over whether I think it can be implemented by adding this to Future<T> withQueryInterceptor<T>(
Future<T> Function() action, {
required QueryInterceptor interceptor,
}) async {
return await resolvedEngine.doWhenOpened((executor) {
final inner = _ExclusiveExecutor(this,
executor: executor.interceptWith(interceptor));
return _runConnectionZoned(inner, action);
});
} (Think because I didn't test this at all). |
That's a great idea! And the API is much cleaner and doesn't complicate existing functionality. In terms of naming, |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, this looks good to me 👍 I've added a brief mention of this feature in the documentation.
I want to be able to intercept queries executed only in certain transaction contexts, and I couldn't find another/easier way.
I thought of filing an issue for this, but it just seemed easier to do.