#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

#36 in Database interfaces

Download history 12393/week @ 2024-01-02 13978/week @ 2024-01-09 17033/week @ 2024-01-16 18517/week @ 2024-01-23 17389/week @ 2024-01-30 13403/week @ 2024-02-06 16854/week @ 2024-02-13 17473/week @ 2024-02-20 14742/week @ 2024-02-27 16648/week @ 2024-03-05 17897/week @ 2024-03-12 19945/week @ 2024-03-19 18988/week @ 2024-03-26 20354/week @ 2024-04-02 20114/week @ 2024-04-09 17488/week @ 2024-04-16

81,697 downloads per month
Used in 66 crates (53 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
~429K SLoC