lemmy/lemmy_db/src/aggregates/comment_aggregates.rs

24 lines
598 B
Rust
Raw Normal View History

2020-12-15 15:28:25 +00:00
use crate::schema::comment_aggregates;
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "comment_aggregates"]
pub struct CommentAggregates {
pub id: i32,
pub comment_id: i32,
pub score: i64,
pub upvotes: i64,
pub downvotes: i64,
}
impl CommentAggregates {
pub fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
comment_aggregates::table
.filter(comment_aggregates::comment_id.eq(comment_id))
.first::<Self>(conn)
}
}
// TODO add tests here