2 use diesel::{dsl::*, result::Error, *};
3 use lemmy_db_schema::{naive_now, source::site::*, PersonId};
5 impl Crud<SiteForm, i32> 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)
22 fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
23 use lemmy_db_schema::schema::site::dsl::*;
24 diesel::delete(site.find(site_id)).execute(conn)
29 fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error>;
30 fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
34 fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error> {
35 use lemmy_db_schema::schema::site::dsl::*;
36 diesel::update(site.find(1))
37 .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
38 .get_result::<Self>(conn)
41 fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
42 use lemmy_db_schema::schema::site::dsl::*;
43 site.first::<Self>(conn)