// mod.rs // // Copyright 2017 Jordan Petridis // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // SPDX-License-Identifier: GPL-3.0-or-later mod new_episode; mod new_show; mod new_source; mod discovery_settings; mod episode; mod show; mod source; pub(crate) use self::discovery_settings::DiscoverySetting; pub(crate) use self::new_episode::{NewEpisode, NewEpisodeMinimal}; pub(crate) use self::new_show::NewShow; pub(crate) use self::new_source::NewSource; #[cfg(test)] pub(crate) use self::new_episode::NewEpisodeBuilder; #[cfg(test)] pub(crate) use self::new_show::NewShowBuilder; pub use self::episode::{ Episode, EpisodeCleanerModel, EpisodeId, EpisodeMinimal, EpisodeModel, EpisodeWidgetModel, }; pub use self::show::{Show, ShowCoverModel, ShowId}; pub use self::source::{Source, SourceId}; #[derive(Debug, Clone, PartialEq)] pub enum IndexState { Index(T), Update((T, ID)), NotChanged, } pub(crate) trait Insert { type Error; fn insert(&self) -> Result; } pub trait Update { type Error; fn update(&self, _: ID) -> Result; } // This might need to change in the future pub trait Index: Insert + Update { type Error; fn index(&self) -> Result>::Error>; } /// FIXME: DOCS pub trait Save { /// The Error type to be returned. type Error; /// Helper method to easily save/"sync" current state of a diesel model to /// the Database. fn save(&self) -> Result; } /// Allows to use struct wrappers instead of i32 Id types. #[macro_export] macro_rules! make_id_wrapper { ($type_name:ident) => { use diesel::backend::Backend; use diesel::deserialize::{self, FromSql}; use diesel::serialize::{self, Output, ToSql}; use diesel::sql_types::Integer; use diesel::sqlite::Sqlite; #[derive(AsExpression, FromSqlRow, Debug, PartialEq, Eq, Hash, Clone, Copy, Default)] #[diesel(sql_type = diesel::sql_types::Integer)] pub struct $type_name(pub i32); impl FromSql for $type_name where DB: Backend, i32: FromSql, { fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result { i32::from_sql(bytes).map($type_name) } } impl ToSql for $type_name { fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Sqlite>) -> serialize::Result { >::to_sql(&self.0, out) } } }; }