mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-18 23:41:09 +00:00
d8722b6e91
* Adding diesel enums for SortType and ListingType - Uses diesel-derive-enum. - Adds diesel.toml , so we can again use the auto-generated schema.rs - Fixes a lot of DB null issues and column ordering issues. - Fixes #1136 - Also replaces RegistrationMode boilerplate. * Fixing unit tests 1. * Remove comment line. * Before patch. * Before again. * Using patch file to fix diesel_ltree issue with diesel.toml * Adding some yalc ignores * Fixing RegistrationMode enums * Adding woodpecker diesel schema check. * Try adding openssl 1. * Try using diesel-cli image 1 * Try using diesel-cli image 2 * Try using diesel-cli image 3 * Try using diesel-cli image 4 * Try using diesel-cli image 5 * Try using diesel-cli image 6 * Try using diesel-cli image 7 * Try using diesel-cli image 8 * Try using diesel-cli image 9 * Try using diesel-cli image 10 * Try using diesel-cli image 11 * Try using diesel-cli image 12 * Try using diesel-cli image 13
32 lines
1 KiB
Rust
32 lines
1 KiB
Rust
use crate::{
|
|
schema::local_site::dsl::local_site,
|
|
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
use diesel::{dsl::insert_into, result::Error};
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
impl LocalSite {
|
|
pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
insert_into(local_site)
|
|
.values(form)
|
|
.get_result::<Self>(conn)
|
|
.await
|
|
}
|
|
pub async fn read(pool: &DbPool) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
local_site.first::<Self>(conn).await
|
|
}
|
|
pub async fn update(pool: &DbPool, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
diesel::update(local_site)
|
|
.set(form)
|
|
.get_result::<Self>(conn)
|
|
.await
|
|
}
|
|
pub async fn delete(pool: &DbPool) -> Result<usize, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
diesel::delete(local_site).execute(conn).await
|
|
}
|
|
}
|