omni_orchestrator/schemas/v1/db/queries/
metrics.rs

1use sqlx::{FromRow, MySql, Pool};
2
3use libomni::types::db::v1 as types;
4use types::metrics::Metric;
5
6pub async fn get_metrics_by_app_id(pool: &Pool<MySql>, app_id: Option<i64>) -> anyhow::Result<Vec<Metric>> {
7    let query = if let Some(app_id) = app_id {
8        sqlx::query_as::<_, Metric>(
9            r#"SELECT id, app_id, metric_name, metric_value, labels, timestamp FROM metrics WHERE app_id = ? "#
10        )
11        .bind(app_id)
12    } else {
13        sqlx::query_as::<_, Metric>(
14            r#"SELECT id, app_id, metric_name, metric_value, labels, timestamp FROM metrics WHERE app_id IS NULL "#
15        )
16    };
17
18    query.fetch_all(pool).await.map_err(Into::into)
19}