use crate::database::pool::shared::pool;
use sqlx::postgres::PgArguments;
use sqlx::query::QueryScalar;
use sqlx::{Decode, Postgres, Type};
pub async fn scalar_one<'q, T>(
query: QueryScalar<'q, Postgres, T, PgArguments>,
) -> Result<T, sqlx::Error>
where
T: Send + Unpin + Type<Postgres> + for<'r> Decode<'r, Postgres>,
{
query.fetch_one(pool().await).await
}
pub async fn scalar_optional<'q, T>(
query: QueryScalar<'q, Postgres, T, PgArguments>,
) -> Result<Option<T>, sqlx::Error>
where
T: Send + Unpin + Type<Postgres> + for<'r> Decode<'r, Postgres>,
{
query.fetch_optional(pool().await).await
}
pub async fn scalar_all<'q, T>(
query: QueryScalar<'q, Postgres, T, PgArguments>,
) -> Result<Vec<T>, sqlx::Error>
where
T: Send + Unpin + Type<Postgres> + for<'r> Decode<'r, Postgres>,
{
query.fetch_all(pool().await).await
}