#connection-pool #sqlite #r2d2 #pool

r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

35 releases (breaking)

0.24.0 Feb 17, 2024
0.23.0 Nov 12, 2023
0.22.0 May 20, 2023
0.21.0 Jul 24, 2022
0.0.1 Jul 22, 2015

#49 in Database interfaces

Download history 17865/week @ 2024-03-14 22435/week @ 2024-03-21 16911/week @ 2024-03-28 21114/week @ 2024-04-04 20857/week @ 2024-04-11 23041/week @ 2024-04-18 25207/week @ 2024-04-25 25987/week @ 2024-05-02 25819/week @ 2024-05-09 24117/week @ 2024-05-16 26654/week @ 2024-05-23 27795/week @ 2024-05-30 24273/week @ 2024-06-06 23154/week @ 2024-06-13 14538/week @ 2024-06-20 10306/week @ 2024-06-27

77,138 downloads per month
Used in 71 crates (54 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

~29MB
~440K SLoC