Skip to main content

dbkit/
lib.rs

1//! Multi-backend database infrastructure.
2//!
3//! Transactional writes go through [sqlx]'s `Any` driver, so the backend
4//! (Postgres, MySQL, or SQLite) is selected from the connection URL scheme.
5//! Analytical reads go through a pluggable Arrow-based engine (DuckDB or
6//! DataFusion), behind feature flags.
7//!
8//! - [`ConnectionManager`] — sqlx connection pool with auto-create DB
9//! - [`Cache`] — DashMap-based concurrent key-value cache with named buckets
10//! - [`BaseHandler`] — `execute_write` (sqlx) / `execute_read` (Arrow) /
11//!   `execute_read_as` (typed), plus transactional → analytical sync
12//! - [`InitializationHandler`] — backend-aware DDL migration executor
13//!
14//! [sqlx]: https://docs.rs/sqlx
15//!
16//! # Example
17//! ```no_run
18//! use dbkit::ConnectionManager;
19//!
20//! # async fn example() -> Result<(), dbkit::DbkitError> {
21//! // The URL scheme selects the backend: postgres:// , mysql:// , sqlite://
22//! let conn = ConnectionManager::new("postgres://localhost/myapp").await?;
23//!
24//! // `pool()` yields a sqlx `AnyPool`, usable across all supported backends.
25//! let _pool = conn.pool();
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! Note: the write/read handlers and migration runner are being ported onto
31//! this pool; see the crate changelog for the current status.
32
33#[cfg(feature = "_arrow")]
34mod analytical;
35mod base_handler;
36mod cache;
37pub mod config;
38mod connection;
39mod error;
40mod initialization;
41#[cfg(feature = "postgres-native")]
42mod pg_handler;
43#[cfg(any(feature = "duckdb", feature = "datafusion"))]
44mod read;
45#[cfg(feature = "clickhouse")]
46mod remote;
47mod value;
48
49pub use base_handler::{BaseHandler, FetchMode, QueryResult, WriteOp};
50pub use cache::Cache;
51pub use config::{Backend, ConfigBuilder, DbkitConfig, SslMode};
52pub use connection::{ConnectionManager, PoolStatus};
53pub use error::DbkitError;
54pub use initialization::InitializationHandler;
55pub use value::DbValue;
56
57// Arrow contract — available whenever any analytical feature is on (embedded
58// engine or remote source). `arrow` is re-exported so callers can inspect
59// `RecordBatch`es with a version-matched arrow.
60#[cfg(feature = "_arrow")]
61pub use analytical::{RecordBatch, arrow};
62
63// Embedded analytical read engines.
64#[cfg(any(feature = "duckdb", feature = "datafusion"))]
65pub use read::ReadEngine;
66
67// Remote analytical sources (read) and sinks (bulk write).
68#[cfg(feature = "clickhouse")]
69pub use remote::{
70    RemoteSink, RemoteSinkExt, RemoteSource, RemoteSourceExt, clickhouse::ClickHouseSource,
71};
72
73// Re-export key sqlx types users will need
74pub use sqlx::{AnyPool, any::AnyRow};
75
76// Native Postgres pool (rich types) — see `ConnectionManager::pg_native_pool`.
77// `PgHandler` is the rich-typed counterpart to `BaseHandler` (binds
78// date/timestamp/json/uuid `DbValue`s natively and returns `PgRow`).
79#[cfg(feature = "postgres-native")]
80pub use pg_handler::PgHandler;
81// `Row` is the trait that provides `PgRow::get` / `try_get`; callers need it in
82// scope to read columns off the `PgRow`s returned by `PgHandler::query`.
83#[cfg(feature = "postgres-native")]
84pub use sqlx::{PgPool, Row, postgres::PgRow};