]> Untitled Git - lemmy.git/blob - lemmy_db/src/aggregates/community_aggregates.rs
9a8ea3658b8bc41048daa9704c50bb7989dbfd4e
[lemmy.git] / lemmy_db / src / aggregates / community_aggregates.rs
1 use crate::schema::community_aggregates;
2 use diesel::{result::Error, *};
3 use serde::Serialize;
4
5 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
6 #[table_name = "community_aggregates"]
7 pub struct CommunityAggregates {
8   pub id: i32,
9   pub community_id: i32,
10   pub subscribers: i64,
11   pub posts: i64,
12   pub counts: i64,
13 }
14
15 impl CommunityAggregates {
16   pub fn read(conn: &PgConnection, id: i32) -> Result<Self, Error> {
17     community_aggregates::table.find(id).first::<Self>(conn)
18   }
19 }
20
21 // TODO add unit tests, to make sure triggers are working