]> Untitled Git - lemmy.git/blob - crates/db_schema/src/impls/community_block.rs
Diesel 2.0.0 upgrade (#2452)
[lemmy.git] / crates / db_schema / src / impls / community_block.rs
1 use crate::{
2   source::community_block::{CommunityBlock, CommunityBlockForm},
3   traits::Blockable,
4 };
5 use diesel::{dsl::*, result::Error, *};
6
7 impl Blockable for CommunityBlock {
8   type Form = CommunityBlockForm;
9   fn block(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
10     use crate::schema::community_block::dsl::*;
11     insert_into(community_block)
12       .values(community_block_form)
13       .on_conflict((person_id, community_id))
14       .do_update()
15       .set(community_block_form)
16       .get_result::<Self>(conn)
17   }
18   fn unblock(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
19     use crate::schema::community_block::dsl::*;
20     diesel::delete(
21       community_block
22         .filter(person_id.eq(community_block_form.person_id))
23         .filter(community_id.eq(community_block_form.community_id)),
24     )
25     .execute(conn)
26   }
27 }