-
Notifications
You must be signed in to change notification settings - Fork 11
Get all Sqlite connections in the pool #101
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # packages/drift_sqlite_async/lib/src/executor.dart # packages/sqlite_async/lib/src/web/database.dart # packages/sqlite_async/lib/src/web/database/web_sqlite_database.dart
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.
One thing I'm wondering about is whether a snapshot of all connections enough - e.g. I could imagine a potential race condition between usages of this call and the pool growing.
Another API which should work as well but might be safer to use could be something like this:
/// Locks all underlying connections making up this database, and gives [block] access to all of them at once.
Future<void> withAllConnections(Future<void> Function(List<({SqliteWriteContext context, bool isReadOnlyConnection})> connections) block);
That also feels a bit clumsy though, so I'm not sure if just exposing all connections directly might be easier for this advanced use-case that realistically requires cooperation with a custom open factory anyway.
@simolus3 We are happy to discuss a different API. Our only use case is the snippet above, and it's only used for attaching/detaching databases. |
Fixes #62
This is a proposal API to fix the linked issue. We have been using it succesfully on our project for the past months. The main goal is to be able to attach a database on all the active connections, read and write. Additionally, we have our own open factory, which knows which databases are attached at any given time, so it will also attach new opened connections.
We use it like this: