45 lines
1.6 KiB
Rust
45 lines
1.6 KiB
Rust
// file: ks-store/src/postgres/query/health_queries.rs
|
|
// version: 4
|
|
|
|
//! PostgreSQL health and diagnostic SQL queries.
|
|
|
|
pub(crate) async fn run_health_check(pool: &sqlx::PgPool) -> ks_core::Result<()> {
|
|
let query_result = sqlx::query_scalar::<sqlx::Postgres, i32>("SELECT 1").fetch_one(pool).await;
|
|
return match query_result {
|
|
std::result::Result::Ok(_value) => std::result::Result::Ok(()),
|
|
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::db(format!(
|
|
"postgres healthcheck failed: {error}"
|
|
))),
|
|
};
|
|
}
|
|
|
|
pub(crate) async fn load_current_schema(
|
|
pool: &sqlx::PgPool,
|
|
) -> ks_core::Result<std::string::String> {
|
|
let query_result =
|
|
sqlx::query_scalar::<sqlx::Postgres, std::string::String>("SELECT current_schema()")
|
|
.fetch_one(pool)
|
|
.await;
|
|
return match query_result {
|
|
std::result::Result::Ok(schema) => std::result::Result::Ok(schema),
|
|
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::db(format!(
|
|
"postgres current schema query failed: {error}"
|
|
))),
|
|
};
|
|
}
|
|
|
|
pub(crate) async fn load_server_version(
|
|
pool: &sqlx::PgPool,
|
|
) -> ks_core::Result<std::string::String> {
|
|
let query_result =
|
|
sqlx::query_scalar::<sqlx::Postgres, std::string::String>("SELECT version()")
|
|
.fetch_one(pool)
|
|
.await;
|
|
return match query_result {
|
|
std::result::Result::Ok(version) => std::result::Result::Ok(version),
|
|
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::db(format!(
|
|
"postgres version query failed: {error}"
|
|
))),
|
|
};
|
|
}
|