#connection-pool #sqlite #r2d2 #pool

hc_r2d2_sqlite

SQLite and SQLCipher support for the r2d2 connection pool

2 unstable releases

0.25.0 Aug 22, 2024
0.24.0 Jun 7, 2024

#1210 in Database interfaces

Download history 432/week @ 2024-10-10 467/week @ 2024-10-17 633/week @ 2024-10-24 636/week @ 2024-10-31 591/week @ 2024-11-07 505/week @ 2024-11-14 511/week @ 2024-11-21 647/week @ 2024-11-28 350/week @ 2024-12-05 571/week @ 2024-12-12 287/week @ 2024-12-19 113/week @ 2024-12-26 455/week @ 2025-01-02 723/week @ 2025-01-09 546/week @ 2025-01-16 581/week @ 2025-01-23

2,351 downloads per month
Used in 26 crates (via holochain_sqlite)

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
~462K SLoC