-use crate::{schema::local_site::dsl::*, source::local_site::*};
-use diesel::{dsl::*, result::Error, *};
+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 fn create(conn: &mut PgConnection, form: &LocalSiteInsertForm) -> Result<Self, Error> {
+ 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 fn read(conn: &mut PgConnection) -> Result<Self, Error> {
- local_site.first::<Self>(conn)
+ pub async fn read(pool: &DbPool) -> Result<Self, Error> {
+ let conn = &mut get_conn(pool).await?;
+ local_site.first::<Self>(conn).await
}
- pub fn update(conn: &mut PgConnection, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
+ 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 fn delete(conn: &mut PgConnection) -> Result<usize, Error> {
- diesel::delete(local_site).execute(conn)
+ pub async fn delete(pool: &DbPool) -> Result<usize, Error> {
+ let conn = &mut get_conn(pool).await?;
+ diesel::delete(local_site).execute(conn).await
}
}