-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Please support sharing a SqliteConnection among threads/tasks #816
Comments
We definitely need a specialized pool for SQLite in SQLx. Connection handle re-use across threads (if enabled and supported) is one thing it could support. Additionally, it could support a reader/writer split pool. 1 connection shared concurrently for writes and M connections for reads. A work-around for any locking issues though is to set the |
Good point, and thanks! The other reason I'd like this is so I can set |
Thread-safe here means that no SQLite's internal structure will be corrupted,
char* sql = "INSERT INTO friends(name) VALUES ('Josh');";
sqlite3_exec(db, sql, 0, 0, 0);
int last_id = sqlite3_last_insert_rowid(db); If you run this code from multiple threads (with different name set on each thread in real example) on the same And this is only a very simple example of many other issues like running INSERTs from Thread A while Thread B started a transaction - those INSERTs will be executed inside this transaction, they won't be queued or whatever people might assume to happen or should happen. As I understand it "serialized" mode was introduced simply because people misused the library too often. Having that said, the following:
is not quite true. You might have a look at #853 - it might be useful for you. |
By default, current versions of sqlite handle concurrent use of the same connection from multiple threads. Would it be possible, given an sqlite compiled to support that, for
SqlitePool
to just hand out the same connection to every thread rather than opening new connections?The text was updated successfully, but these errors were encountered: