#sqlite #r2d2 #pool

r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

32 releases (21 breaking)

0.21.0 Jul 24, 2022
0.20.0 Feb 27, 2022
0.19.0 Oct 6, 2021
0.18.0 Apr 9, 2021
0.0.1 Jul 22, 2015

#43 in Database interfaces

Download history 8441/week @ 2022-10-07 7367/week @ 2022-10-14 8291/week @ 2022-10-21 9976/week @ 2022-10-28 10004/week @ 2022-11-04 8929/week @ 2022-11-11 9419/week @ 2022-11-18 10135/week @ 2022-11-25 7590/week @ 2022-12-02 8722/week @ 2022-12-09 9113/week @ 2022-12-16 5615/week @ 2022-12-23 5926/week @ 2022-12-30 9289/week @ 2023-01-06 9977/week @ 2023-01-13 10893/week @ 2023-01-20

37,144 downloads per month
Used in 54 crates (33 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

~24MB
~441K SLoC