1 use crate::structs::PersonBlockView;
2 use diesel::{result::Error, *};
5 schema::{person, person_alias_1, person_block},
6 source::person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
7 traits::{ToSafe, ViewToVec},
10 type PersonBlockViewTuple = (PersonSafe, PersonSafeAlias1);
12 impl PersonBlockView {
13 pub fn for_person(conn: &PgConnection, person_id: PersonId) -> Result<Vec<Self>, Error> {
14 let res = person_block::table
15 .inner_join(person::table)
16 .inner_join(person_alias_1::table) // TODO I dont know if this will be smart abt the column
18 Person::safe_columns_tuple(),
19 PersonAlias1::safe_columns_tuple(),
21 .filter(person_block::person_id.eq(person_id))
22 .order_by(person_block::published)
23 .load::<PersonBlockViewTuple>(conn)?;
25 Ok(Self::from_tuple_to_vec(res))
29 impl ViewToVec for PersonBlockView {
30 type DbTuple = PersonBlockViewTuple;
31 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
38 .collect::<Vec<Self>>()