#sqlite #r2d2 #pool

r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

31 releases (20 breaking)

0.20.0 Feb 27, 2022
0.19.0 Oct 6, 2021
0.18.0 Apr 9, 2021
0.17.0 Sep 7, 2020
0.0.1 Jul 22, 2015

#199 in Database interfaces

Download history 8851/week @ 2022-03-11 7517/week @ 2022-03-18 7472/week @ 2022-03-25 7685/week @ 2022-04-01 7945/week @ 2022-04-08 5988/week @ 2022-04-15 6908/week @ 2022-04-22 7126/week @ 2022-04-29 9100/week @ 2022-05-06 10072/week @ 2022-05-13 10800/week @ 2022-05-20 8535/week @ 2022-05-27 9157/week @ 2022-06-03 9826/week @ 2022-06-10 11651/week @ 2022-06-17 9933/week @ 2022-06-24

41,506 downloads per month
Used in 28 crates (24 directly)

MIT license

7KB
83 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

~25MB
~465K SLoC