2 aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
3 diesel::BoolExpressionMethods,
4 newtypes::{PersonId, PostId},
5 schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
6 utils::{get_conn, DbPool},
8 use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
9 use diesel_async::RunQueryDsl;
11 impl PersonPostAggregates {
13 pool: &mut DbPool<'_>,
14 form: &PersonPostAggregatesForm,
15 ) -> Result<Self, Error> {
16 let conn = &mut get_conn(pool).await?;
17 insert_into(person_post_aggregates)
19 .on_conflict((person_id, post_id))
22 .get_result::<Self>(conn)
26 pool: &mut DbPool<'_>,
29 ) -> Result<Self, Error> {
30 let conn = &mut get_conn(pool).await?;
31 person_post_aggregates
32 .filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))