Crates.io | deadpool-sqlite |
lib.rs | deadpool-sqlite |
version | 0.9.0 |
source | src |
created_at | 2021-05-30 12:59:32.858836 |
updated_at | 2024-10-24 09:47:33.212076 |
description | Dead simple async pool for rusqlite |
homepage | |
repository | https://github.com/bikeshedder/deadpool |
max_upload_size | |
id | 403824 |
size | 27,099 |
Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for rusqlite
and provides a wrapper that ensures correct use of the connection
inside a separate thread.
Feature | Description | Extra dependencies | Default |
---|---|---|---|
rt_tokio_1 |
Enable support for tokio crate | deadpool/rt_tokio_1 |
yes |
rt_async-std_1 |
Enable support for async-std crate | deadpool/rt_async-std_1 |
no |
serde |
Enable support for serde crate | deadpool/serde , serde/derive |
no |
tracing |
Enable support for tracing by propagating Spans in the interact() calls. Enable this if you use the tracing crate and you want to get useful traces from within interact() calls. |
deadpool-sync/tracing , tracing |
no |
use deadpool_sqlite::{Config, Runtime};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut cfg = Config::new("db.sqlite3");
let pool = cfg.create_pool(Runtime::Tokio1).unwrap();
let conn = pool.get().await.unwrap();
let result: i64 = conn
.interact(|conn| {
let mut stmt = conn.prepare("SELECT 1")?;
let mut rows = stmt.query([])?;
let row = rows.next()?.unwrap();
row.get(0)
})
.await??;
assert_eq!(result, 1);
Ok(())
}
Licensed under either of
at your option.