2022-11-09 10:05:00 +00:00
|
|
|
use crate::{
|
2022-11-19 04:33:54 +00:00
|
|
|
schema::local_site::dsl::local_site,
|
2023-04-17 19:19:51 +00:00
|
|
|
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, DbPool},
|
|
|
|
};
|
2023-04-17 19:19:51 +00:00
|
|
|
use diesel::{dsl::insert_into, result::Error};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2022-10-27 09:24:07 +00:00
|
|
|
|
|
|
|
impl LocalSite {
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn create(pool: &mut DbPool<'_>, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-10-27 09:24:07 +00:00
|
|
|
insert_into(local_site)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-10-27 09:24:07 +00:00
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn read(pool: &mut DbPool<'_>) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
local_site.first::<Self>(conn).await
|
2022-10-27 09:24:07 +00:00
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn update(pool: &mut DbPool<'_>, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2022-10-27 09:24:07 +00:00
|
|
|
diesel::update(local_site)
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await
|
2022-10-27 09:24:07 +00:00
|
|
|
}
|
2023-07-11 13:09:59 +00:00
|
|
|
pub async fn delete(pool: &mut DbPool<'_>) -> Result<usize, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
|
|
|
diesel::delete(local_site).execute(conn).await
|
2022-10-27 09:24:07 +00:00
|
|
|
}
|
|
|
|
}
|