#bb8

bb8-surrealdb

SurrealDB driver for bb8 based on the surrealdb crate

4 releases

0.1.3 Nov 9, 2022
0.1.2 Oct 28, 2022
0.1.1 Oct 27, 2022
0.1.0 Oct 27, 2022

#1443 in Database interfaces

21 downloads per month

MIT license

6KB
73 lines

bb8-surrealdb

SurrealDB support for bb8 based on the surrealdb crate.

Installing

Make sure to add bb8 and bb8-surrealdb to your Cargo.toml, like:

[dependencies]
bb8 = "0.8"
bb8-surrealdb = "0.1.2"
surrealdb = "1.0.0-beta.8"

Example

use bb8::Pool;
use bb8_surrealdb::SurrealdbConnectionManager;
use surrealdb::Session;
use futures_util::join_all;

#[tokio::main]
async fn main() {
    let pool = Pool::builder()
        .max_size(5)
        .build(
            SurrealdbConnectionManager::tikv(
                "localhost:2379",
                Session::for_kv().with_ns("test").with_db("test")
            ).await
        )
        .await
        .unwrap();

    for _i in 0..10 {
        let pool = pool.clone();

        handles.push(tokio::spawn(async move {
            let conn = pool.get().await.unwrap();

            conn.execute("SELECT * from user;", None, false).await.unwrap();
        }))
    }

    join_all(handles).await;
}

Important Note

This crate is really only useful if compiling with the tikv feature, as you cannot have multiple instances of a connection to an in memory embedded database or multiple instances of a connection to a file based store due to file locks. This feature has not been included by default to allow compilation as the surreal crate with the tikv feature does not compile on windows, and only compiles on other platforms if GCC 8 specifically is installed.

License

bb8-surrealdb is primarily distributed under the terms of the MIT license.

See LICENSE for details.

Dependencies

~47–83MB
~1.5M SLoC