lemmy/lemmy_db/src/aggregates/community_aggregates.rs

22 lines
579 B
Rust
Raw Normal View History

2020-12-04 21:35:46 +00:00
use crate::schema::community_aggregates;
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "community_aggregates"]
pub struct CommunityAggregates {
pub id: i32,
pub community_id: i32,
pub subscribers: i64,
pub posts: i64,
pub counts: i64,
}
impl CommunityAggregates {
pub fn read(conn: &PgConnection, id: i32) -> Result<Self, Error> {
community_aggregates::table.find(id).first::<Self>(conn)
}
}
// TODO add unit tests, to make sure triggers are working