#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

#90 in Database interfaces

Download history 12156/week @ 2024-07-18 11376/week @ 2024-07-25 12213/week @ 2024-08-01 12143/week @ 2024-08-08 11589/week @ 2024-08-15 11314/week @ 2024-08-22 10864/week @ 2024-08-29 11356/week @ 2024-09-05 12297/week @ 2024-09-12 12214/week @ 2024-09-19 10848/week @ 2024-09-26 10278/week @ 2024-10-03 10965/week @ 2024-10-10 13640/week @ 2024-10-17 13162/week @ 2024-10-24 16276/week @ 2024-10-31

56,233 downloads per month
Used in 77 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

~27MB
~442K SLoC