Expand description
§Deadpool for CitadelDB
Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for citadeldb
and provides async connection pooling via the blocking thread pool.
§Features
| 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 |
§Example
use deadpool_citadeldb::{Config, Runtime};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg = Config::new("", b"secret");
let pool = cfg.create_pool(Runtime::Tokio1)?;
let conn = pool.get().await?;
let result: i64 = conn
.interact(|inner| {
inner.execute("CREATE TABLE IF NOT EXISTS t (id INTEGER PRIMARY KEY, name TEXT)")
.expect("Failed to create table");
let result = inner.query("SELECT 1")
.expect("Failed to query");
let row = result.rows.first().expect("No rows returned");
let val = row.first().expect("Empty row");
match val {
citadel_sql::Value::Integer(i) => *i,
_ => panic!("Expected integer"),
}
})
.await?;
assert_eq!(result, 1);
Ok(())
}§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Re-exports§
pub use config::Config;pub use config::ConfigError;pub use citadel;pub use citadel_sql;
Modules§
- config
- Configuration support.
Structs§
- Manager
Managerfor creating and recycling CitadelDB connections.- Metrics
- Statistics regarding an object returned by the pool
- Object
Id - A unique identifier for an object within a pool.
- Pool
Config Poolconfiguration.- Status
- The current pool status.
- Sync
Guard - This guard is returned when calling
SyncWrapper::lockorSyncWrapper::try_lock. This is basically just a wrapper around aMutexGuardbut hides some implementation details. - Timeouts
- Timeouts when getting
Objects from aPool.
Enums§
- Error
- Error type for
deadpool-citadeldb. - Interact
Error - Possible errors returned when
SyncWrapper::interact()fails. - Runtime
- Enumeration for picking a runtime implementation.
- Timeout
Type - Possible steps causing the timeout in an error returned by
Pool::get()method.
Type Aliases§
- Build
Error - Type alias for using
deadpool::managed::BuildErrorwith [citadeldb]. - Connection
- Type alias for
Object - Create
Pool Error - Type alias for using
deadpool::managed::CreatePoolErrorwith [citadeldb]. - Hook
- Type alias for using
deadpool::managed::Hookwith [citadeldb]. - Hook
Error - Type alias for using
deadpool::managed::HookErrorwith [citadeldb]. - Object
- Type alias for using
deadpool::managed::Objectwith [citadeldb]. - Pool
- Type alias for using
deadpool::managed::Poolwith [citadeldb]. - Pool
Builder - Type alias for using
deadpool::managed::PoolBuilderwith [citadeldb]. - Pool
Error - Type alias for using
deadpool::managed::PoolErrorwith [citadeldb]. - Weak
Pool - Type alias for using
deadpool::managed::Poolwith [citadeldb].