Skip to main content

systemprompt_analytics/repository/costs/
mod.rs

1//! Cost analytics repository.
2//!
3//! Aggregates microdollar-precision AI request costs from `ai_requests`.
4//! [`platform`] holds platform-wide rollups; [`per_user`] holds the
5//! user-scoped cost and conversation-context queries.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10mod per_user;
11mod platform;
12
13use sqlx::PgPool;
14use std::sync::Arc;
15use systemprompt_database::DbPool;
16
17#[derive(Debug, Clone)]
18pub struct CostAnalyticsRepository {
19    pool: Arc<PgPool>,
20}
21
22impl CostAnalyticsRepository {
23    pub fn new(db: &DbPool) -> Self {
24        let pool = db.pool();
25        Self { pool }
26    }
27
28    #[must_use]
29    pub const fn from_pool(pool: Arc<PgPool>) -> Self {
30        Self { pool }
31    }
32}