Crate deadpool_sqlite

Source
Expand description

§Deadpool for SQLite Latest Version Unsafe forbidden Rust 1.75+

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.

§Features

FeatureDescriptionExtra dependenciesDefault
rt_tokio_1Enable support for tokio cratedeadpool/rt_tokio_1yes
rt_async-std_1Enable support for async-std cratedeadpool/rt_async-std_1no
serdeEnable support for serde cratedeadpool/serde, serde/deriveno
tracingEnable 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, tracingno

§Example

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(())
}

§License

Licensed under either of

at your option.

Re-exports§

pub use rusqlite;

Structs§

Config
Configuration object.
Manager
Manager for creating and recycling SQLite Connections.
Metrics
Statistics regarding an object returned by the pool
PoolConfig
Pool configuration.
Status
The current pool status.
SyncGuard
This guard is returned when calling SyncWrapper::lock or SyncWrapper::try_lock. This is basicly just a wrapper around a MutexGuard but hides some implementation details.
Timeouts
Timeouts when getting Objects from a Pool.

Enums§

InteractError
Possible errors returned when SyncWrapper::interact() fails.
Runtime
Enumeration for picking a runtime implementation.

Type Aliases§

BuildError
Type alias for using deadpool::managed::BuildError with rusqlite.
ConfigError
This error is returned if there is something wrong with the SQLite configuration.
Connection
Type alias for Object
CreatePoolError
Type alias for using deadpool::managed::CreatePoolError with rusqlite.
Hook
Type alias for using deadpool::managed::Hook with rusqlite.
HookError
Type alias for using deadpool::managed::HookError with rusqlite.
Object
Type alias for using deadpool::managed::Object with rusqlite.
Pool
Type alias for using deadpool::managed::Pool with rusqlite.
PoolBuilder
Type alias for using deadpool::managed::PoolBuilder with rusqlite.
PoolError
Type alias for using deadpool::managed::PoolError with rusqlite.