#connection-pool #sqlite #r2d2 #pool

r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

36 releases (breaking)

0.25.0 Jul 21, 2024
0.24.0 Feb 17, 2024
0.23.0 Nov 12, 2023
0.22.0 May 20, 2023
0.0.1 Jul 22, 2015

#96 in Database interfaces

Download history 11513/week @ 2024-08-19 11461/week @ 2024-08-26 10371/week @ 2024-09-02 11975/week @ 2024-09-09 11663/week @ 2024-09-16 12671/week @ 2024-09-23 10113/week @ 2024-09-30 9952/week @ 2024-10-07 13039/week @ 2024-10-14 12770/week @ 2024-10-21 16806/week @ 2024-10-28 12771/week @ 2024-11-04 48414/week @ 2024-11-11 15836/week @ 2024-11-18 27681/week @ 2024-11-25 18825/week @ 2024-12-02

111,446 downloads per month
Used in 78 crates (59 directly)

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
~441K SLoC