arcature_db/db/sqlx.rs
1use sqlx::PgPool;
2
3use super::Db;
4
5impl Db {
6 /// Get the underlying [`sqlx::PgPool`] for raw SQLx access.
7 ///
8 /// This is the first-class SQLx escape hatch (Phase 4 spec ยง5). Use it
9 /// with `sqlx::query!` / `sqlx::query_as!` for compile-time checked SQL,
10 /// or with the runtime `sqlx::query_as` for dynamically-built queries:
11 ///
12 /// ```no_run
13 /// # use arcature_db::Db;
14 /// use arcature_db::sqlx;
15 ///
16 /// #[derive(sqlx::FromRow)]
17 /// struct UserRow { id: i32, email: String }
18 ///
19 /// # async fn example(db: &Db) -> Result<(), sqlx::Error> {
20 /// let row = sqlx::query_as::<_, UserRow>("SELECT id, email FROM users WHERE id = $1")
21 /// .bind(42)
22 /// .fetch_one(db.sqlx())
23 /// .await?;
24 /// # Ok(())
25 /// # }
26 /// ```
27 pub fn sqlx(&self) -> &PgPool {
28 &self.pool
29 }
30}