Skip to main content

es_entity/
db.rs

1//! Centralized database type aliases.
2//!
3//! Re-exports PostgreSQL-specific types from [`sqlx`] under shorter names,
4//! giving the rest of the crate a single place to reference them.
5
6pub use sqlx::PgConnection as Connection;
7pub use sqlx::PgPool as Pool;
8pub use sqlx::Postgres as Db;
9pub use sqlx::postgres::{
10    PgArgumentBuffer as ArgumentBuffer, PgRow as Row, PgTypeInfo as TypeInfo,
11};
12
13/// Fetches the current timestamp from the database via `SELECT NOW()`.
14pub async fn database_now(
15    executor: impl sqlx::Executor<'_, Database = Db>,
16) -> Result<chrono::DateTime<chrono::Utc>, sqlx::Error> {
17    sqlx::query_scalar::<_, chrono::DateTime<chrono::Utc>>("SELECT NOW()")
18        .fetch_one(executor)
19        .await
20}