Skip to main content

objectiveai_cli/db/
pool.rs

1//! Newtype wrapper around `sqlx::PgPool` so the CLI's
2//! [`crate::context::Context`] holds a domain-typed handle.
3//!
4//! Construction is private to this crate via [`super::init::init`]; the
5//! pool itself is concurrency-safe so callers can hold `&Pool`
6//! everywhere a sqlite `Arc<Mutex<Connection>>` used to be threaded.
7
8use sqlx::PgPool;
9
10#[derive(Debug, Clone)]
11pub struct Pool(pub(crate) PgPool);
12
13impl std::ops::Deref for Pool {
14    type Target = PgPool;
15    fn deref(&self) -> &PgPool {
16        &self.0
17    }
18}
19
20/// The live pool PLUS the admin coordinates it was built from —
21/// what [`super::compartment`] needs to mint derived per-plugin
22/// connection strings. Cached as a unit by `Context::db_client`;
23/// the password stays in memory exactly as long as the pool it
24/// authenticated.
25#[derive(Debug, Clone)]
26pub struct DbHandle {
27    pub pool: Pool,
28    /// `host:port` of the server (no scheme, no credentials).
29    pub address: String,
30    pub admin_user: String,
31    pub admin_password: String,
32    /// Application database name.
33    pub database: String,
34}