2 use diesel::{dsl::*, result::Error, *};
3 use lemmy_db_schema::{naive_now, source::site::*};
5 impl Crud<SiteForm> for Site {
6 fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
7 use lemmy_db_schema::schema::site::dsl::*;
8 site.first::<Self>(conn)
11 fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
12 use lemmy_db_schema::schema::site::dsl::*;
13 insert_into(site).values(new_site).get_result::<Self>(conn)
16 fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
17 use lemmy_db_schema::schema::site::dsl::*;
18 diesel::update(site.find(site_id))
20 .get_result::<Self>(conn)
25 fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
29 fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error> {
30 use lemmy_db_schema::schema::site::dsl::*;
31 diesel::update(site.find(1))
32 .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
33 .get_result::<Self>(conn)