#connection-pool #sqlite #r2d2 #pool #connection-manager

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

#987 in Database interfaces

Download history 133/week @ 2024-06-01 174/week @ 2024-06-08 197/week @ 2024-06-15 163/week @ 2024-06-22 356/week @ 2024-06-29 471/week @ 2024-07-06 491/week @ 2024-07-13 212/week @ 2024-07-20 537/week @ 2024-07-27 712/week @ 2024-08-03 542/week @ 2024-08-10 751/week @ 2024-08-17 691/week @ 2024-08-24

2,790 downloads per month
Used in 23 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
~453K SLoC