Crate r2d2_sqlite

source ·
Expand description

§Sqlite support for the r2d2 connection pool.

Library crate: r2d2-sqlite

Integrated with: r2d2 and rusqlite


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();
        .execute("CREATE TABLE IF NOT EXISTS foo (bar INTEGER)", params![])

        .map(|i| {
            let pool = pool.clone();
            thread::spawn(move || {
                let conn = pool.get().unwrap();
                conn.execute("INSERT INTO foo (bar) VALUES (?)", &[&i])
        .collect::<Result<_, _>>()