]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/impls/person.rs
Diesel 2.0.0 upgrade (#2452)
[lemmy.git] / crates / db_schema / src / impls / person.rs
index 6e4398f6834fafcc3fcb051b79daf80fcd7c06ee..de99d4b63dc2223a58daa749636ea9085a34404a 100644 (file)
@@ -66,124 +66,26 @@ mod safe_type {
   }
 }
 
-mod safe_type_alias_1 {
-  use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe};
-
-  type Columns = (
-    id,
-    name,
-    display_name,
-    avatar,
-    banned,
-    published,
-    updated,
-    actor_id,
-    bio,
-    local,
-    banner,
-    deleted,
-    inbox_url,
-    shared_inbox_url,
-    matrix_user_id,
-    admin,
-    bot_account,
-    ban_expires,
-  );
-
-  impl ToSafe for PersonAlias1 {
-    type SafeColumns = Columns;
-    fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        name,
-        display_name,
-        avatar,
-        banned,
-        published,
-        updated,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-        inbox_url,
-        shared_inbox_url,
-        matrix_user_id,
-        admin,
-        bot_account,
-        ban_expires,
-      )
-    }
-  }
-}
-
-mod safe_type_alias_2 {
-  use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe};
-
-  type Columns = (
-    id,
-    name,
-    display_name,
-    avatar,
-    banned,
-    published,
-    updated,
-    actor_id,
-    bio,
-    local,
-    banner,
-    deleted,
-    inbox_url,
-    shared_inbox_url,
-    matrix_user_id,
-    admin,
-    bot_account,
-    ban_expires,
-  );
-
-  impl ToSafe for PersonAlias2 {
-    type SafeColumns = Columns;
-    fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        name,
-        display_name,
-        avatar,
-        banned,
-        published,
-        updated,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-        inbox_url,
-        shared_inbox_url,
-        matrix_user_id,
-        admin,
-        bot_account,
-        ban_expires,
-      )
-    }
-  }
-}
-
 impl Crud for Person {
   type Form = PersonForm;
   type IdType = PersonId;
-  fn read(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
+  fn read(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
     person
       .filter(deleted.eq(false))
       .find(person_id)
       .first::<Self>(conn)
   }
-  fn delete(conn: &PgConnection, person_id: PersonId) -> Result<usize, Error> {
+  fn delete(conn: &mut PgConnection, person_id: PersonId) -> Result<usize, Error> {
     diesel::delete(person.find(person_id)).execute(conn)
   }
-  fn create(conn: &PgConnection, form: &PersonForm) -> Result<Self, Error> {
+  fn create(conn: &mut PgConnection, form: &PersonForm) -> Result<Self, Error> {
     insert_into(person).values(form).get_result::<Self>(conn)
   }
-  fn update(conn: &PgConnection, person_id: PersonId, form: &PersonForm) -> Result<Self, Error> {
+  fn update(
+    conn: &mut PgConnection,
+    person_id: PersonId,
+    form: &PersonForm,
+  ) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(form)
       .get_result::<Self>(conn)
@@ -192,7 +94,7 @@ impl Crud for Person {
 
 impl Person {
   pub fn ban_person(
-    conn: &PgConnection,
+    conn: &mut PgConnection,
     person_id: PersonId,
     ban: bool,
     expires: Option<chrono::NaiveDateTime>,
@@ -202,19 +104,23 @@ impl Person {
       .get_result::<Self>(conn)
   }
 
-  pub fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Self, Error> {
+  pub fn add_admin(
+    conn: &mut PgConnection,
+    person_id: PersonId,
+    added: bool,
+  ) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(admin.eq(added))
       .get_result::<Self>(conn)
   }
 
-  pub fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
+  pub fn mark_as_updated(conn: &mut PgConnection, person_id: PersonId) -> Result<Person, Error> {
     diesel::update(person.find(person_id))
       .set((last_refreshed_at.eq(naive_now()),))
       .get_result::<Self>(conn)
   }
 
-  pub fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
+  pub fn delete_account(conn: &mut PgConnection, person_id: PersonId) -> Result<Person, Error> {
     use crate::schema::local_user;
 
     // Set the local user info to none
@@ -238,7 +144,7 @@ impl Person {
       .get_result::<Self>(conn)
   }
 
-  pub fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
+  pub fn upsert(conn: &mut PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
     insert_into(person)
       .values(person_form)
       .on_conflict(actor_id)
@@ -248,7 +154,7 @@ impl Person {
   }
 
   pub fn update_deleted(
-    conn: &PgConnection,
+    conn: &mut PgConnection,
     person_id: PersonId,
     new_deleted: bool,
   ) -> Result<Person, Error> {
@@ -258,13 +164,16 @@ impl Person {
       .get_result::<Self>(conn)
   }
 
-  pub fn leave_admin(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
+  pub fn leave_admin(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(admin.eq(false))
       .get_result::<Self>(conn)
   }
 
-  pub fn remove_avatar_and_banner(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
+  pub fn remove_avatar_and_banner(
+    conn: &mut PgConnection,
+    person_id: PersonId,
+  ) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set((
         avatar.eq::<Option<String>>(None),
@@ -283,7 +192,7 @@ pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool
 }
 
 impl ApubActor for Person {
-  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+  fn read_from_apub_id(conn: &mut PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
     use crate::schema::person::dsl::*;
     Ok(
       person
@@ -296,7 +205,7 @@ impl ApubActor for Person {
   }
 
   fn read_from_name(
-    conn: &PgConnection,
+    conn: &mut PgConnection,
     from_name: &str,
     include_deleted: bool,
   ) -> Result<Person, Error> {
@@ -311,7 +220,7 @@ impl ApubActor for Person {
   }
 
   fn read_from_name_and_domain(
-    conn: &PgConnection,
+    conn: &mut PgConnection,
     person_name: &str,
     protocol_domain: &str,
   ) -> Result<Person, Error> {
@@ -329,7 +238,7 @@ mod tests {
 
   #[test]
   fn test_crud() {
-    let conn = establish_unpooled_connection();
+    let conn = &mut establish_unpooled_connection();
 
     let new_person = PersonForm {
       name: "holly".into(),
@@ -337,7 +246,7 @@ mod tests {
       ..PersonForm::default()
     };
 
-    let inserted_person = Person::create(&conn, &new_person).unwrap();
+    let inserted_person = Person::create(conn, &new_person).unwrap();
 
     let expected_person = Person {
       id: inserted_person.id,
@@ -363,9 +272,9 @@ mod tests {
       ban_expires: None,
     };
 
-    let read_person = Person::read(&conn, inserted_person.id).unwrap();
-    let updated_person = Person::update(&conn, inserted_person.id, &new_person).unwrap();
-    let num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
+    let read_person = Person::read(conn, inserted_person.id).unwrap();
+    let updated_person = Person::update(conn, inserted_person.id, &new_person).unwrap();
+    let num_deleted = Person::delete(conn, inserted_person.id).unwrap();
 
     assert_eq!(expected_person, read_person);
     assert_eq!(expected_person, inserted_person);