use std::path::Path;
use bb8_rusqlite::RusqliteConnectionManager;
use rusqlite::named_params;
use tempfile::NamedTempFile;
use tokio::task;
async fn example(path: &Path) -> anyhow::Result<()> {
let manager = RusqliteConnectionManager::new(path);
let pool = bb8::Pool::builder().build(manager).await?;
let conn = pool.get().await?;
let value = task::block_in_place(move || -> anyhow::Result<i32> {
conn.execute("CREATE TABLE t (a INTEGER)", [])?;
conn.execute(
"INSERT INTO t (a) VALUES (:a)",
named_params! {
":a": 42,
},
)?;
Ok(conn.query_row("SELECT a FROM t", [], |row| row.get(0))?)
})?;
println!("we stored this value: {}", value);
Ok(())
}
fn main() -> anyhow::Result<()> {
let temp = NamedTempFile::new()?;
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async { example(temp.path()).await })?;
drop(rt);
Ok(())
}