Skip to main content

dbkit_rs/
lib.rs

1//! Reusable Postgres + DuckDB database infrastructure.
2//!
3//! Provides the foundational components for projects that use Postgres for
4//! writes and optionally DuckDB for analytical reads:
5//!
6//! - [`ConnectionManager`] — Postgres connection pool with auto-create DB
7//! - [`Cache`] — DashMap-based concurrent key-value cache with named buckets
8//! - [`BaseHandler`] — Unified `execute_write` (Postgres) / `execute_read` (DuckDB)
9//! - [`InitializationHandler`] — Batch DDL migration executor
10//!
11//! # Example
12//! ```no_run
13//! use dbkit::{ConnectionManager, BaseHandler, InitializationHandler};
14//!
15//! # async fn example() -> Result<(), dbkit::DbkitError> {
16//! let conn = ConnectionManager::new("postgres://localhost/myapp").await?;
17//! let pool = std::sync::Arc::new(conn.pool().clone());
18//!
19//! // Run migrations
20//! let init = InitializationHandler::new(pool.clone());
21//! let sql = "CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name TEXT)";
22//! init.run_migrations(sql).await?;
23//!
24//! // Use the handler for queries
25//! let handler = BaseHandler::new(pool);
26//! # Ok(())
27//! # }
28//! ```
29
30mod base_handler;
31mod cache;
32pub mod config;
33mod connection;
34mod error;
35mod initialization;
36
37pub use base_handler::{BaseHandler, FetchMode, QueryResult, WriteOp};
38pub use cache::Cache;
39pub use config::{ConfigBuilder, DbkitConfig, SslMode};
40pub use connection::{ConnectionManager, PoolStatus};
41pub use error::DbkitError;
42pub use initialization::InitializationHandler;
43
44// DuckDB types only available with the feature
45#[cfg(feature = "duckdb")]
46pub use base_handler::{DuckParam, ReadOp, ReadResult, RecordBatch};
47
48// Re-export key types users will need
49pub use deadpool_postgres::Pool;
50pub use tokio_postgres::Row as PgRow;