cardamon 0.0.2

Cardamon is a tool to help development teams measure the power consumption and carbon emissions of their software.
use crate::entities::metrics;
use anyhow::{self, Context};
use sea_orm::*;

pub async fn fetch_within(
    run: i32,
    from: i64,
    to: i64,
    db: &DatabaseConnection,
) -> anyhow::Result<Vec<metrics::Model>> {
    let query = metrics::Entity::find().filter(
        Condition::all()
            .add(metrics::Column::RunId.eq(run))
            .add(metrics::Column::TimeStamp.gte(from))
            .add(metrics::Column::TimeStamp.lte(to)),
    );

    query.all(db).await.context(format!(
        "Error fetching metrics gathered between: {} and {}",
        from, to
    ))
}