2 unstable releases

0.18.0 Oct 4, 2021
0.1.0 Apr 24, 2023

#2654 in Database interfaces

Download history 332/week @ 2023-12-18 116/week @ 2023-12-25 147/week @ 2024-01-01 492/week @ 2024-01-08 534/week @ 2024-01-15 501/week @ 2024-01-22 487/week @ 2024-01-29 794/week @ 2024-02-05 222/week @ 2024-02-12 407/week @ 2024-02-19 494/week @ 2024-02-26 700/week @ 2024-03-04 425/week @ 2024-03-11 848/week @ 2024-03-18 416/week @ 2024-03-25 477/week @ 2024-04-01

2,212 downloads per month
Used in 23 crates (via holochain_sqlite)

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

~21–28MB
~429K SLoC