ryanfowler / async-sqlite

A Rust library to interact with sqlite from an async context.
MIT License
8 stars 4 forks source link

question + maybe-open-discussions? #13

Open jessekrubin opened 1 month ago

jessekrubin commented 1 month ago

Hi @ryanfowler,

Still loving this library! but I have some question(s) and would like to pick your brain. Might be nice to open up github-discussions?

questions:

ryanfowler commented 1 month ago

Hey! I just enabled discussions, so feel free to ask questions over there 😄

To answer the questions:

Cloning a Client is very cheap. The way a Client works under the hood is that a sqlite connection is opened in a dedicated thread, and the client communicates with that thread asynchronously to run your provided function there with the rusqlite connection. So when a Client is cloned, it's essentially just copying a reference to that thread/connection.

This means that although a Client can be shared across threads and used asynchronously at the same time, only one function can actually be run with the rusqlite connection at a time. As long as one function is still running, no other functions can run on that connection. For your question about creating an async stream, what is your use case? Are you trying to incrementally stream a blob out of your db?

jessekrubin commented 1 month ago

@ryanfowler thanks! Very good to know!

This is what I ended up with for the tile-stream: https://github.com/jessekrubin/utiles/blob/main/crates/utiles/src/mbt/tiles_stream.rs

I really could not say if that is a good or bad way of doing it, but it does seem to work, and it is VERY fast. The using async streams for map-tiles is pretty ideal seeming (afaict) because what I am using this for often involves receiving/sending a huge number of rows to/from a database often with totally inconsistent timing.