dbkit-rs
Reusable Postgres + DuckDB database infrastructure for Rust applications.
Features
- Connection pooling —
ConnectionManagerwraps deadpool-postgres with auto-create database, configurable pool size, and timeouts - Configurable —
DbkitConfigbuilder with connection string construction, SSL modes, and pool tuning - Unified query executor —
BaseHandlerfor Postgres writes (WriteOp) and optional DuckDB analytical reads (ReadOp) - Migration tracking —
InitializationHandlerwith named migrations tracked by content hash - Concurrent cache — DashMap-based key-value cache with named buckets
- Optional DuckDB — behind a
duckdbfeature flag to avoid the heavy bundled build when not needed
Usage
use ;
use Arc;
// Connect with defaults
let conn = new.await?;
// Or use the config builder
let config = builder
.host
.database
.user
.password
.pool_size
.build;
let conn = connect.await?;
let pool = new;
// Run tracked migrations
let init = new;
init.run_named_migration.await?;
// Query
let handler = new;
Pool health
let status = conn.pool_status;
println!;
println!;
DuckDB reads (optional)
Enable the duckdb feature:
= { = "0.1", = ["duckdb"] }
use ;
let handler = with_duckdb?;
let result = handler.execute_read.await?;
Cache
use Cache;
let cache = with_buckets;
cache.set;
let val = cache.get;
Feature flags
| Feature | Default | Description |
|---|---|---|
duckdb |
off | Enables DuckDB analytical reads via BaseHandler::with_duckdb() |
License
MIT