sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

sharing connection between threads

Open attelmalagate opened this issue 3 years ago • 1 comments

Great light weight library! I'm trying to use share a Connection between threads (with sqlite::Connection::open_with_flags and flag set_full_mutex() which corresponds to the serialized multi-thread mode of sqlite3, which allows sharing a connection between threads - works well in C) The sqlite connection is wrapped in an Arc and rustc gives the "(dyn FnMut(usize) -> bool + 'static) cannot be shared between threads safely" error with "note: required because of the requirements on the impl of Send for Arc<Connection>" Am I missing something? The sqlite serialized mode is allowed in open_with_flags so it would be logical to allow sharing the connection between threads Thanks!

attelmalagate avatar Jan 22 '22 16:01 attelmalagate

Hello, thank you for the question! I think it was added along with several other flags, and nobody really tested this particular scenario. Please feel free to correct and open a pull request.

IvanUkhov avatar Jan 23 '22 08:01 IvanUkhov

It is available as of 0.27.2. Here is an example:

https://github.com/stainless-steel/sqlite/blob/main/tests/lib.rs#L81-L99

IvanUkhov avatar Oct 22 '22 12:10 IvanUkhov