1 个不稳定版本
0.1.1 | 2023年4月10日 |
---|---|
0.1.0 |
|
#2923 in 数据库接口
8KB
91 行
r2d2-sqlite-pool
r2d2连接池,从https://github.com/ivanceras/r2d2-sqlite分叉而来。
lib.rs
:
为r2d2
连接池提供SQLite支持。
库Crates:r2d2_sqlite_pool
示例
extern crate r2d2;
extern crate r2d2_sqlite_pool;
extern crate rusqlite;
use std::thread;
use r2d2_sqlite_pool::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()
}
依赖
~28MB
~437K SLoC