Open justinturpin opened 3 years ago
This is mentioned in https://github.com/eaze/tide-sqlx/pull/4/commits/570dbc13de940054ab1a19dae57cb3a5754fc98d, but should be in the docs. This is unfortunately impossible to support in current Tide. All middleware must be able to be Send + Sync + 'static
- that is, it must be thread safe, due to async-std
's threaded futures executor.
One day, when we can do borrows for futures properly and tide's middleware signature looks more like
AsyncFn(&mut Request, ...)
then perhaps this will be possible, although the general consensus is that doing so requires async closures in the language, something which has been mentioned but for which there is not yet an RFC to my knowledge.
I have opened https://github.com/launchbadge/sqlx/issues/920 over on the SQLx repo, but it is up to you for any investment if you want this!
Cool thanks, I figured it was something non-trivial like this. I'll poke around the Sqlx codebase and see what it might take to make the Sqlite connection sync. I think theoretically Sqlite can have multiple threads be read-only, and only one thread can get write access, so maybe theres something with an Arc<RwLock
Currently the crate doesn't work with sqlite, or if it does the interface is different for it:
Fails to compile with:
I'm guessing this is do to weirdness around Sqlite itself not being thread safe, and Sqlx does some thread-wrapping trickery. I'd be happy to take a look and try and fix this if someone had some ideas about where to go to do this. I'm playing around with a small Tide web app right now to try and figure out the best approach to having an app that uses Sqlite for many readers but only one writer.