Skip to main content

arcature_db/db/
ty.rs

1use sqlx::PgPool;
2
3/// The Arcature database handle: one PostgreSQL connection pool with two
4/// first-class data paths.
5///
6/// `Db` holds exactly one [`sqlx::PgPool`] and derives the SeaORM
7/// [`DatabaseConnection`](sea_orm::DatabaseConnection) over the same pool via
8/// `SqlxPostgresConnector::from_sqlx_postgres_pool`. There is never a second
9/// pool (Phase 4 spec §4).
10///
11/// `Db` is `Clone + Send + Sync + 'static` so it works as normal Axum state
12/// (Phase 4 spec §8):
13///
14/// ```no_run
15/// # use arcature_db::Db;
16/// #[derive(Clone)]
17/// struct AppState { db: Db }
18/// ```
19///
20/// There is no `DbExtractor`, service container, database registry, global
21/// singleton, `TypeId`/`Any` map, thread-local, or task-local (Phase 4 spec
22/// §8, §20). Use [`Db::sqlx`] for raw SQL access and [`Db::orm`] for SeaORM
23/// access — both over the same pool.
24#[derive(Clone)]
25pub struct Db {
26    pub(crate) pool: PgPool,
27    pub(crate) orm: sea_orm::DatabaseConnection,
28}
29
30impl Db {
31    pub(crate) fn from_pool_orm(pool: PgPool, orm: sea_orm::DatabaseConnection) -> Self {
32        Self { pool, orm }
33    }
34}