#r2d2 #connection-pool #sqlite

r2d2_sqlite_neonphog

Sqlite support for the r2d2 connection pool

2 unstable releases

0.18.0 Oct 4, 2021
0.1.0 Apr 24, 2023

#2256 in Database interfaces

Download history 186/week @ 2024-07-01 328/week @ 2024-07-08 666/week @ 2024-07-15 189/week @ 2024-07-22 229/week @ 2024-07-29 170/week @ 2024-08-05 91/week @ 2024-08-12 58/week @ 2024-08-19 64/week @ 2024-08-26 60/week @ 2024-09-02 62/week @ 2024-09-09 63/week @ 2024-09-16 131/week @ 2024-09-23 89/week @ 2024-09-30 9/week @ 2024-10-07 62/week @ 2024-10-14

298 downloads per month

MIT license

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

~27MB
~443K SLoC