1use super::*;
2use crate::Result;
3use anyhow::Context as _;
4
5impl LlmDatabase {
6 pub async fn get_billing_events(&self) -> Result<Vec<(billing_event::Model, model::Model)>> {
7 self.transaction(|tx| async move {
8 let events_with_models = billing_event::Entity::find()
9 .find_also_related(model::Entity)
10 .all(&*tx)
11 .await?;
12 events_with_models
13 .into_iter()
14 .map(|(event, model)| {
15 let model =
16 model.context("could not find model associated with billing event")?;
17 Ok((event, model))
18 })
19 .collect()
20 })
21 .await
22 }
23
24 pub async fn consume_billing_event(&self, id: BillingEventId) -> Result<()> {
25 self.transaction(|tx| async move {
26 billing_event::Entity::delete_by_id(id).exec(&*tx).await?;
27 Ok(())
28 })
29 .await
30 }
31}