usage.rs

 1use crate::{
 2    db::UserId,
 3    llm::db::{ModelId, UsageId, UsageMeasureId},
 4};
 5use sea_orm::entity::prelude::*;
 6
 7/// An LLM usage record.
 8#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
 9#[sea_orm(table_name = "usages")]
10pub struct Model {
11    #[sea_orm(primary_key)]
12    pub id: UsageId,
13    /// The ID of the Zed user.
14    ///
15    /// Corresponds to the `users` table in the primary collab database.
16    pub user_id: UserId,
17    pub model_id: ModelId,
18    pub measure_id: UsageMeasureId,
19    pub timestamp: DateTime,
20    pub buckets: Vec<i64>,
21    pub is_staff: bool,
22}
23
24#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
25pub enum Relation {
26    #[sea_orm(
27        belongs_to = "super::model::Entity",
28        from = "Column::ModelId",
29        to = "super::model::Column::Id"
30    )]
31    Model,
32    #[sea_orm(
33        belongs_to = "super::usage_measure::Entity",
34        from = "Column::MeasureId",
35        to = "super::usage_measure::Column::Id"
36    )]
37    UsageMeasure,
38}
39
40impl Related<super::model::Entity> for Entity {
41    fn to() -> RelationDef {
42        Relation::Model.def()
43    }
44}
45
46impl Related<super::usage_measure::Entity> for Entity {
47    fn to() -> RelationDef {
48        Relation::UsageMeasure.def()
49    }
50}
51
52impl ActiveModelBehavior for ActiveModel {}