2 use crate::schema::site;
4 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
9 pub description: Option<String>,
11 pub published: chrono::NaiveDateTime,
12 pub updated: Option<chrono::NaiveDateTime>,
13 pub enable_downvotes: bool,
14 pub open_registration: bool,
15 pub enable_nsfw: bool,
18 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
19 #[table_name = "site"]
22 pub description: Option<String>,
24 pub updated: Option<chrono::NaiveDateTime>,
25 pub enable_downvotes: bool,
26 pub open_registration: bool,
27 pub enable_nsfw: bool,
30 impl Crud<SiteForm> for Site {
31 fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
32 use crate::schema::site::dsl::*;
33 site.first::<Self>(conn)
36 fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
37 use crate::schema::site::dsl::*;
38 diesel::delete(site.find(site_id)).execute(conn)
41 fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
42 use crate::schema::site::dsl::*;
43 insert_into(site).values(new_site).get_result::<Self>(conn)
46 fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
47 use crate::schema::site::dsl::*;
48 diesel::update(site.find(site_id))
50 .get_result::<Self>(conn)