Skip to content

question + maybe-open-discussions? #13

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

Open
jessekrubin opened this issue Jul 19, 2024 · 2 comments
Open

question + maybe-open-discussions? #13

jessekrubin opened this issue Jul 19, 2024 · 2 comments

Comments

@jessekrubin
Copy link
Contributor

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:

  • Do you know a straight forward way to create an async-stream from a query?
  • Is cloning an async-sqlite client a bad idea? I figured out a way to make an async-stream from a client but it involves cloning the client if you/one does not want to consume their client.
  • How costly is cloning a client?
@ryanfowler
Copy link
Owner

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
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants