mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 00:43:59 +00:00
80aef61aed
More fixes - fixed docker builds - fixed mentions regex test - fixed DATABASE_URL stuff - change schema path in diesel.toml Address review comments - add jsonb column back into activity table - remove authors field from cargo.toml - adjust LEMMY_DATABASE_URL env var usage - rename all occurences of LEMMY_DATABASE_URL to DATABASE_URL Decouple utils and db Split code into cargo workspaces Co-authored-by: Felix Ableitner <me@nutomic.com> Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/67
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use crate::{schema::site, Crud};
|
|
use diesel::{dsl::*, result::Error, *};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
|
#[table_name = "site"]
|
|
pub struct Site {
|
|
pub id: i32,
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub creator_id: i32,
|
|
pub published: chrono::NaiveDateTime,
|
|
pub updated: Option<chrono::NaiveDateTime>,
|
|
pub enable_downvotes: bool,
|
|
pub open_registration: bool,
|
|
pub enable_nsfw: bool,
|
|
}
|
|
|
|
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
|
#[table_name = "site"]
|
|
pub struct SiteForm {
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub creator_id: i32,
|
|
pub updated: Option<chrono::NaiveDateTime>,
|
|
pub enable_downvotes: bool,
|
|
pub open_registration: bool,
|
|
pub enable_nsfw: bool,
|
|
}
|
|
|
|
impl Crud<SiteForm> for Site {
|
|
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
|
|
use crate::schema::site::dsl::*;
|
|
site.first::<Self>(conn)
|
|
}
|
|
|
|
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
|
|
use crate::schema::site::dsl::*;
|
|
diesel::delete(site.find(site_id)).execute(conn)
|
|
}
|
|
|
|
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
|
|
use crate::schema::site::dsl::*;
|
|
insert_into(site).values(new_site).get_result::<Self>(conn)
|
|
}
|
|
|
|
fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
|
|
use crate::schema::site::dsl::*;
|
|
diesel::update(site.find(site_id))
|
|
.set(new_site)
|
|
.get_result::<Self>(conn)
|
|
}
|
|
}
|