use serde_json::Value;
use sqlx::Row;
use sqlx::postgres::{PgPool, PgRow};
use sqlx::types::JsonValue;
pub async fn list_api_registry_entries(pool: &PgPool) -> Result<Vec<Value>, String> {
let rows: Vec<PgRow> = sqlx::query(
r#"
SELECT to_jsonb(t) AS row_json
FROM api_registry t
"#,
)
.fetch_all(pool)
.await
.map_err(|err| {
format!("Failed to fetch list_api_registry_entries data from athena_logging: {err}")
})?;
rows.into_iter()
.map(|row| {
row.try_get::<JsonValue, _>("row_json").map_err(|err| {
format!("Failed to decode list_api_registry_entries row from athena_logging: {err}")
})
})
.collect::<Result<Vec<Value>, String>>()
}
pub async fn get_api_registry_by_id(
pool: &PgPool,
api_registry_id: &str,
) -> Result<Vec<Value>, String> {
let rows: Vec<PgRow> = sqlx::query(
r#"
SELECT to_jsonb(t) AS row_json
FROM api_registry t
WHERE t.api_registry_id::text = $1
"#,
)
.bind(api_registry_id)
.fetch_all(pool)
.await
.map_err(|err| {
format!(
"Failed to fetch api_registry by id {} from athena_logging: {:?}",
api_registry_id, err
)
})?;
rows.into_iter()
.map(|row| {
row.try_get::<JsonValue, _>("row_json").map_err(|err| {
format!("Failed to decode api_registry row from athena_logging: {err}")
})
})
.collect::<Result<Vec<Value>, String>>()
}