Skip to main content

tonin_core/traits/
database.rs

1//! Database capability.
2//!
3//! Intentionally tiny — the framework's job is to hand the service a
4//! connection URL + a label for telemetry. Typed access is the user's
5//! DB client crate (sqlx, sea-orm), which already emits its own spans
6//! when an OTel tracer provider is installed (`tonin-telemetry::init`
7//! installs one). We do not reinvent a DB API on top.
8
9use async_trait::async_trait;
10
11/// Marker trait for a framework-managed connection pool. Reserved
12/// surface — no impl ships in Phase 3. Concrete pool plumbing is a
13/// service-author decision until someone genuinely asks for it.
14pub trait AnyPool: Send + Sync + 'static {}
15
16#[async_trait]
17pub trait Database: Send + Sync + 'static {
18    /// Connection URL — e.g. `postgres://user:pass@host:5432/db`.
19    /// Per design Q4, default impls read this from the `DATABASE_URL`
20    /// env var the deployment template injects.
21    fn url(&self) -> &str;
22
23    /// Optional framework-managed pool. Default `None`.
24    fn pool(&self) -> Option<&dyn AnyPool> {
25        None
26    }
27
28    /// Span attribute `db.system`. Implementations return one of
29    /// `"postgres" | "mysql" | "sqlite" | "clickhouse"`.
30    fn system(&self) -> &'static str;
31}