Skip to content
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

Allow QueryInterceptor to ignore/exclude specified tables #2999

Closed
CyMathew opened this issue May 8, 2024 · 1 comment
Closed

Allow QueryInterceptor to ignore/exclude specified tables #2999

CyMathew opened this issue May 8, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@CyMathew
Copy link

CyMathew commented May 8, 2024

Is your feature request related to a problem? Please describe.
I'm trying to build a naive offline-first sync logic by storing all database operations on the client in a log table before attempting to sync the operations with a remote server. If I use the QueryInterceptor to intercept all operations and insert into log table I'd create an infinite loop of insert -> intercept -> insert, unless I string-parse the table names from the statement string and avoid logging when log table statements are intercepted. I was wondering if it would be possible to exclude a set of tables from being intercepted from the API side.

(Btw, thank you for building QueryInterceptor. I thought I would have to manually parse SQL for a little while before I found this gem buried in the Drift docs).

Describe the solution you'd like
A way to manage which tables are intercepted by QueryInterceptor by defining a set of tables that are excluded from being intercepted. Either at the class level or at the .interceptWith() level would work.

class LogInterceptor extends QueryInterceptor {

...

  @override
  Set<Table>? get excludedTables => {TableX, TableY};
}

or

...
return NativeDatabase.createInBackground(file, logStatements: true)
                     .interceptWith(LogInterceptor(), excludedTables: {TableX, TableY})
...
@CyMathew CyMathew added the enhancement New feature or request label May 8, 2024
@simolus3
Copy link
Owner

simolus3 commented May 8, 2024

This excludedTables getter would also have to work for custom inserts being passed to runInsert, and we simply don't have the information about the table available there.

table I'd create an infinite loop of insert -> intercept -> insert

Hm, if you have a second database instance that points to the same underlying query executor but without the interceptor you'd be fine, right? Then you can use that database for the sole purpose maintaining the log table.

An alternative would be to use the sqlparser package to parse the statements and determine the table through that - but I think sidestepping the interceptor by using a second database is the easier approach.

@simolus3 simolus3 closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants