#connection-pool

hc_r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

2 unstable releases

0.25.0 Aug 22, 2024
0.24.0 Jun 7, 2024

#27 in #connection-pool

Download history 208/week @ 2024-07-21 550/week @ 2024-07-28 722/week @ 2024-08-04 548/week @ 2024-08-11 744/week @ 2024-08-18 628/week @ 2024-08-25 618/week @ 2024-09-01 703/week @ 2024-09-08 794/week @ 2024-09-15 808/week @ 2024-09-22 504/week @ 2024-09-29 467/week @ 2024-10-06 496/week @ 2024-10-13 512/week @ 2024-10-20 704/week @ 2024-10-27 611/week @ 2024-11-03

2,330 downloads per month
Used in 24 crates (via holochain_sqlite)

MIT license

9KB
102 lines

r2d2-sqlite

Latest Version Build Status MIT licensed

r2d2 connection pool for sqlite based on Steven Fackler's r2d2-postgres.

Documentation


lib.rs:

Sqlite support for the r2d2 connection pool.

Library crate: r2d2-sqlite

Integrated with: r2d2 and rusqlite

Example

extern crate r2d2;
extern crate r2d2_sqlite;
extern crate rusqlite;

use std::thread;
use r2d2_sqlite::SqliteConnectionManager;
use rusqlite::params;

fn main() {
    let manager = SqliteConnectionManager::file("file.db");
    let pool = r2d2::Pool::new(manager).unwrap();
    pool.get()
        .unwrap()
        .execute("CREATE TABLE IF NOT EXISTS foo (bar INTEGER)", params![])
        .unwrap();

    (0..10)
        .map(|i| {
            let pool = pool.clone();
            thread::spawn(move || {
                let conn = pool.get().unwrap();
                conn.execute("INSERT INTO foo (bar) VALUES (?)", &[&i])
                    .unwrap();
            })
        })
        .collect::<Vec<_>>()
        .into_iter()
        .map(thread::JoinHandle::join)
        .collect::<Result<_, _>>()
        .unwrap()
}

Dependencies

~28MB
~455K SLoC