#sqlite #r2d2 #pool

r2d2_sqlite

Sqlite support for the r2d2 connection pool

23 releases (12 breaking)

0.12.0 Aug 2, 2019
0.11.0 Jun 28, 2019
0.10.0 May 13, 2019
0.8.0 Jan 15, 2019
0.0.1 Jul 22, 2015

#44 in Database interfaces

Download history 835/week @ 2019-04-19 1081/week @ 2019-04-26 2182/week @ 2019-05-03 2649/week @ 2019-05-10 486/week @ 2019-05-17 597/week @ 2019-05-24 740/week @ 2019-05-31 407/week @ 2019-06-07 392/week @ 2019-06-14 822/week @ 2019-06-21 1221/week @ 2019-06-28 2021/week @ 2019-07-05 1337/week @ 2019-07-12 1770/week @ 2019-07-19 2484/week @ 2019-07-26

5,535 downloads per month
Used in 11 crates (8 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

~11MB
~211K SLoC