arcature_db/db/ping.rs
1use super::Db;
2use crate::error::DbHealthError;
3
4impl Db {
5 /// Check database liveness by executing `SELECT 1`.
6 ///
7 /// Uses the configured pool acquire timeout; it does not hide a 30-second
8 /// timeout (Phase 4 spec §28). A closed pool returns
9 /// [`DbHealthError::Closed`]. The ping error preserves the upstream
10 /// `sqlx::Error` for source chaining. Credentials are never included in
11 /// the failure (Phase 4 spec §28).
12 pub async fn ping(&self) -> Result<(), DbHealthError> {
13 if self.pool.is_closed() {
14 return Err(DbHealthError::Closed);
15 }
16 sqlx::query("SELECT 1")
17 .execute(&self.pool)
18 .await
19 .map(|_| ())
20 .map_err(|source| DbHealthError::Ping { source })
21 }
22}