#connection-pool #bb8-connection #bb8 #connection-manager #sqlite #pool

bin+lib bb8-libsql

A simple connection pooling manager for libsql using bb8

3 releases

0.1.2 Aug 22, 2024
0.1.1 Aug 16, 2024
0.1.0 Aug 15, 2024

#1986 in Database interfaces

MIT license

16KB
146 lines

bb8-libsql

A simple connection pooling manager for libsql using bb8.


lib.rs:

Sqlite support for the bb8 connection pool.

Library crate: bb8-libsql

Integrated with: bb8 and libsql

Example

use std::{env, error::Error};
use r2d2_libsql::LibsqlConnectionManager;
 
use dotenvy::dotenv;
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    dotenv().ok();
 
    let url = env::var("LIBSQL_CLIENT_URL").unwrap();
    let token = env::var("LIBSQL_CLIENT_TOKEN").unwrap();
 
    let manager = LibsqlConnectionManager::remote(&url, &token);
    let pool = bb8::Pool::builder()
        .max_size(15)
        .build(manager)
        .await
        .unwrap();
 
    let conn = pool.get().await?;
    let mut rows = conn.query("SELECT 1;", ()).await?;
 
    let value_found = rows.next().await?
        .map(|row| row.get::<u64>(0))
        .transpose()?;
 
    dbg!(value_found);
 
    Ok(())
}

Dependencies

~4–10MB
~104K SLoC