//! //! use super::{models, schema::api_kgon_synchronizations}; use diesel::prelude::*; use diesel::result::Error; /// pub struct Repository {} impl std::fmt::Debug for Repository { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.debug_struct("Repository of api_kgon_synchronizations") .finish() } } impl Default for Repository { fn default() -> Self { Self::new() } } impl Repository { /// pub fn new() -> Repository { Repository {} } /// pub fn insert( &self, conn: &diesel::PgConnection, new_member: &models::NewSynchronization, ) -> Result { let inserted = diesel::insert_into(api_kgon_synchronizations::table) .values(new_member) .get_result::(conn)?; Ok(inserted) } /// pub fn select( &self, conn: &diesel::PgConnection, id: i32, ) -> Result, Error> { match api_kgon_synchronizations::table .find(id) .first::(conn) { Ok(m) => Ok(Some(m)), Err(e) => match e { diesel::result::Error::NotFound => Ok(None), _ => Err(e), }, } } /// pub fn select_by_item( &self, conn: &diesel::PgConnection, item: String, ) -> Result, Error> { use api_kgon_synchronizations::dsl; match api_kgon_synchronizations::table .filter(dsl::item.eq(item)) .first::(conn) { Ok(m) => Ok(Some(m)), Err(e) => match e { diesel::result::Error::NotFound => Ok(None), _ => Err(e), }, } } /// pub fn update( &self, conn: &diesel::PgConnection, id: i32, modify: &models::ModifySynchronization, ) -> Result { use api_kgon_synchronizations::dsl; diesel::update(dsl::api_kgon_synchronizations.filter(dsl::id.eq(id))) .set(modify) .execute(conn) .map(|c| c as u64) } /// pub fn delete(&self, conn: &diesel::PgConnection, id: i32) -> Result { use api_kgon_synchronizations::dsl; diesel::delete(api_kgon_synchronizations::table.filter(dsl::id.eq(id))) .execute(conn) .map(|c| c as u64) } }