Expand description
§Deadpool for libsql

Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for libsql.
§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 |
All of the features of libsql are also re-exported.
For example, the feature core does enable the feature core from the libsql crate.
§Example
use std::sync::Arc;
use deadpool_libsql::{Manager, Pool};
use deadpool_libsql::libsql::{Builder, params};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = deadpool_libsql::libsql::Builder::new_local("libsql.db")
.build()
.await?;
let manager = Manager::from_libsql_database(db);
let pool = Pool::builder(manager).build()?;
let conn = pool.get().await?;
let mut rows = conn.query("SELECT 1", params![]).await?;
let row = rows.next().await?.unwrap();
let result: i64 = row.get(0)?;
Ok(())
}§Example with config and dotenvy crate
# .env
LIBSQL__DATABASE=Local
LIBSQL__PATH=deadpool.dbⓘ
use deadpool_libsql::{libsql::params, Runtime};
use dotenvy::dotenv;
#[derive(Debug, serde::Deserialize)]
struct Config {
libsql: deadpool_libsql::Config,
}
impl Config {
pub fn from_env() -> Result<Self, config::ConfigError> {
config::Config::builder()
.add_source(config::Environment::default().separator("__"))
.build()?
.try_deserialize()
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let cfg = Config::from_env().expect("Invalid config");
let pool = cfg.libsql.create_pool(Some(Runtime::Tokio1)).await?;
for i in 1..10i64 {
let conn = pool.get().await?;
let mut rows = conn.query("SELECT 1 + $1", params![i]).await?;
let row = rows.next().await?.unwrap();
let value: i64 = row.get(0)?;
assert_eq!(value, i + 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§
Modules§
- config
- This module contains all the configuration structures
Structs§
- Manager
Managerfor creating and recyclinglibsql::Connection.- Metrics
- Statistics regarding an object returned by the pool
- Pool
Config Poolconfiguration.- Status
- The current pool status.
- Timeouts
- Timeouts when getting
Objects from aPool.
Enums§
- Connection
Error - This error is returned when the connection fails
- Runtime
- Enumeration for picking a runtime implementation.
Type Aliases§
- Build
Error - Type alias for using
deadpool::managed::BuildErrorwithlibsql. - Connection
- Type alias for [‘Object’]
- Create
Pool Error - Type alias for using
deadpool::managed::CreatePoolErrorwithlibsql. - Hook
- Type alias for using
deadpool::managed::Hookwithlibsql. - Hook
Error - Type alias for using
deadpool::managed::HookErrorwithlibsql. - Object
- Type alias for using
deadpool::managed::Objectwithlibsql. - Pool
- Type alias for using
deadpool::managed::Poolwithlibsql. - Pool
Builder - Type alias for using
deadpool::managed::PoolBuilderwithlibsql. - Pool
Error - Type alias for using
deadpool::managed::PoolErrorwithlibsql.