#sqlite #r2d2 #pool

r2d2_sqlite

Sqlite support for the r2d2 connection pool

27 releases (16 breaking)

✓ Uses Rust 2018 edition

new 0.16.0 May 23, 2020
0.14.0 Jan 19, 2020
0.13.0 Dec 19, 2019
0.12.0 Aug 2, 2019
0.0.1 Jul 22, 2015

#73 in Database interfaces

Download history 1659/week @ 2020-01-25 2113/week @ 2020-02-01 1828/week @ 2020-02-08 1544/week @ 2020-02-15 821/week @ 2020-02-22 1160/week @ 2020-02-29 1023/week @ 2020-03-07 1086/week @ 2020-03-14 1301/week @ 2020-03-21 1410/week @ 2020-03-28 1443/week @ 2020-04-04 1468/week @ 2020-04-11 1696/week @ 2020-04-18 1022/week @ 2020-04-25 937/week @ 2020-05-02 960/week @ 2020-05-09

5,300 downloads per month
Used in 19 crates (15 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
~198K SLoC