tursodatabase / libsql-client-rs

libSQL Rust client library can be used to communicate with sqld natively over HTTP protocol with native Rust interface.
MIT License
75 stars 27 forks source link

Allow creating HTTP client without going through the generic client #26

Closed rylev closed 1 year ago

rylev commented 1 year ago

For my use case, I only ever want to use the HTTP client, however it seems I'm currently forced to go through the generic client construction code path. This wouldn't really be an issue, but the generic client construction is async because the hrana client needs it - even though I'm not using it. Additionally, the generic client is not Clone while the HTTP one is. This impacts my code which does not expect sqld client construction to be async and expects to be able to clone the client. I could work around these issues (by using tokio::Runtime::block_on and Arc), but it makes my code much more complicated.

Would it be possible to make construction of the HTTP client public so that I can directly use that?

psarna commented 1 year ago

@rylev Sure thing! Just published 0.31.5 with some of the pub(crate) constructors published as pub. The following will work to create a sync reqwest-based client:

    use libsql_client::{Client, http, reqwest};
    let inner = http::InnerClient::Reqwest(reqwest::HttpClient::new());
    let client = Client::Http(http::Client::from_env(inner)?);
rylev commented 1 year ago

Awesome. Thank you for the quick response! 🎉