0xSiO / bolt-rs

Communicate with Bolt-compatible graph databases in Rust! ⚡🔩
Mozilla Public License 2.0
80 stars 7 forks source link

usage example #16

Closed againstplag2022 closed 1 year ago

againstplag2022 commented 1 year ago

Thank you very much for open sourcing this. This is definitely useful. Is it possible that a usage example being provided for this library? I tried to make the example here to work, but keep getting errors like the following:

let stream = BufStream::new(stream).compat();
    |                  -------------- ^^^^^^ the trait `std::io::Read` is not implemented for `bolt_client::Stream`
    |                  |
    |                  required by a bound introduced by this call

currently I have this in my cargo.toml file:

bufstream = "0.1"
bolt-client = {version = "0.10.0", features = ["tokio-stream"]}

and I have imports like this:

use bolt_client::*;
use bufstream::BufStream;
use bolt_proto::{message::*, value::*, version::*, Message, Value};

Not sure whether my cargo or import statements are correct. Would be great if a full example can be provided.

timshoaf commented 1 year ago

Have you: use tokio_util::compat::*; ?

againstplag2022 commented 1 year ago

yeah, same error

againstplag2022 commented 1 year ago

the following worked for testing:

[dependencies]
tokio = { version = "1.14.0", features = ["full"] }
bolt-client = {version = "0.10.1", features =["tokio-stream"]}

[dev-dependencies.tokio-util]
features = ["compat"]
version = "0.6.0" 

and importing like the original example.

0xSiO commented 1 year ago

Hey @againstplag2022, These libraries use asynchronous I/O, so you can't use synchronous I/O libraries like bufstream. The Stream struct I've provided via the tokio-stream feature implements the AsyncRead and AsyncWrite traits, and you can wrap it in a tokio BufStream as in the example.

However, if you're working on an application and you just need a way to easily get connections to your database, you should be using a connection pool instead, like deadpool, bb8, or mobc. I've published adapter crates for each of those three libraries. Here's an example of what using a connection pool might look like for a web application.

Let me know if you have any other questions!