#pool #r2d2 #sqlite

r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

39 releases (breaking)

0.28.0 Apr 23, 2025
0.27.0 Mar 8, 2025
0.26.0 Jan 19, 2025
0.25.0 Jul 21, 2024
0.0.1 Jul 22, 2015

#40 in Database interfaces

Download history 20720/week @ 2025-01-13 54747/week @ 2025-01-20 20759/week @ 2025-01-27 23024/week @ 2025-02-03 22305/week @ 2025-02-10 30545/week @ 2025-02-17 31225/week @ 2025-02-24 15368/week @ 2025-03-03 19064/week @ 2025-03-10 16662/week @ 2025-03-17 17080/week @ 2025-03-24 35078/week @ 2025-03-31 25243/week @ 2025-04-07 24710/week @ 2025-04-14 30858/week @ 2025-04-21 30596/week @ 2025-04-28

112,780 downloads per month
Used in 97 crates (71 directly)

MIT license

10KB
102 lines

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()
}

r2d2-sqlite

Latest Version Build Status MIT licensed

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

Documentation

Dependencies

~27MB
~438K SLoC