2 use diesel::{dsl::*, result::Error, *};
3 use lemmy_db_schema::{naive_now, source::site::*, PersonId};
8 fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
9 use lemmy_db_schema::schema::site::dsl::*;
10 site.first::<Self>(conn)
13 fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
14 use lemmy_db_schema::schema::site::dsl::*;
15 insert_into(site).values(new_site).get_result::<Self>(conn)
18 fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
19 use lemmy_db_schema::schema::site::dsl::*;
20 diesel::update(site.find(site_id))
22 .get_result::<Self>(conn)
24 fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
25 use lemmy_db_schema::schema::site::dsl::*;
26 diesel::delete(site.find(site_id)).execute(conn)
31 fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error>;
32 fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
36 fn transfer(conn: &PgConnection, new_creator_id: PersonId) -> Result<Site, Error> {
37 use lemmy_db_schema::schema::site::dsl::*;
38 diesel::update(site.find(1))
39 .set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
40 .get_result::<Self>(conn)
43 fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
44 use lemmy_db_schema::schema::site::dsl::*;
45 site.first::<Self>(conn)