From e4d77a6ba42e9f43594e7a4dadf96abed6fc2610 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 13 Jan 2018 07:46:56 +0200 Subject: [PATCH] Cleanup the id() method mess of the diesel models. --- Cargo.lock | 2 -- hammond-data/src/dbqueries.rs | 4 ++-- hammond-data/src/feed.rs | 5 ++--- hammond-data/src/models/insertables.rs | 2 +- hammond-data/src/models/queryables.rs | 14 ++++++++++++-- hammond-downloader/Cargo.toml | 4 ---- hammond-downloader/src/downloader.rs | 3 +-- hammond-downloader/src/errors.rs | 2 -- hammond-downloader/src/lib.rs | 1 - hammond-gtk/Cargo.toml | 4 ---- hammond-gtk/src/main.rs | 1 - hammond-gtk/src/manager.rs | 5 ++--- hammond-gtk/src/utils.rs | 3 +-- hammond-gtk/src/views/shows.rs | 1 - hammond-gtk/src/widgets/show.rs | 1 - 15 files changed, 21 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7b7883..091ed0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -559,7 +559,6 @@ dependencies = [ name = "hammond-downloader" version = "0.1.0" dependencies = [ - "diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hammond-data 0.1.0", @@ -575,7 +574,6 @@ name = "hammond-gtk" version = "0.1.0" dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-pixbuf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index 65236d6..bf89235 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -232,8 +232,8 @@ pub fn remove_feed(pd: &Podcast) -> Result<()> { con.transaction(|| -> Result<()> { delete_source(&con, pd.source_id())?; - delete_podcast(&con, *pd.id())?; - delete_podcast_episodes(&con, *pd.id())?; + delete_podcast(&con, pd.id())?; + delete_podcast_episodes(&con, pd.id())?; info!("Feed removed from the Database."); Ok(()) }) diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 8fa4fc9..fc86ca2 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -4,7 +4,6 @@ use rayon::prelude::*; use diesel::prelude::*; use rayon::iter::IntoParallelIterator; -use diesel::associations::Identifiable; use rss; use dbqueries; @@ -75,7 +74,7 @@ impl Feed { let items = self.channel.items(); let new_episodes: Vec<_> = items .par_iter() - .filter_map(|item| parser::new_episode(item, *pd.id()).ok()) + .filter_map(|item| parser::new_episode(item, pd.id()).ok()) .collect(); new_episodes @@ -203,7 +202,7 @@ mod tests { let feed = fs::File::open(path).unwrap(); // parse it into a channel let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap(); - Feed::from_channel_source(chan, *s.id()) + Feed::from_channel_source(chan, s.id()) }) .collect(); diff --git a/hammond-data/src/models/insertables.rs b/hammond-data/src/models/insertables.rs index 8f2689a..e66f54f 100644 --- a/hammond-data/src/models/insertables.rs +++ b/hammond-data/src/models/insertables.rs @@ -113,7 +113,7 @@ impl NewPodcast { if (foo.link() != self.link) || (foo.title() != self.title) || (foo.image_uri() != self.image_uri.as_ref().map(|x| x.as_str())) { - self.update(&con, *foo.id())?; + self.update(&con, foo.id())?; } } Err(_) => { diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 863d51a..7c40be0 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -451,6 +451,11 @@ pub struct Podcast { } impl Podcast { + /// Get the Feed `id`. + pub fn id(&self) -> i32 { + self.id + } + /// Get the Feed `title`. pub fn title(&self) -> &str { &self.title @@ -551,7 +556,7 @@ pub struct PodcastCoverQuery { impl From for PodcastCoverQuery { fn from(p: Podcast) -> PodcastCoverQuery { PodcastCoverQuery { - id: *p.id(), + id: p.id(), title: p.title, image_uri: p.image_uri, } @@ -592,6 +597,11 @@ pub struct Source { } impl<'a> Source { + /// Get the source `id` column. + pub fn id(&self) -> i32 { + self.id + } + /// Represents the location(usually url) of the Feed xml file. pub fn uri(&self) -> &str { &self.uri @@ -739,7 +749,7 @@ impl<'a> Source { client: &'a mut Client>, ignore_etags: bool, ) -> Box + 'a> { - let id = *self.id(); + let id = self.id(); let feed = request_constructor(&self, client, ignore_etags) .map(move |res| { println!("Status: {}", res.status()); diff --git a/hammond-downloader/Cargo.toml b/hammond-downloader/Cargo.toml index f541ba8..ada57e7 100644 --- a/hammond-downloader/Cargo.toml +++ b/hammond-downloader/Cargo.toml @@ -13,9 +13,5 @@ reqwest = "0.8.2" tempdir = "0.3.5" glob = "0.2.11" -[dependencies.diesel] -features = ["sqlite"] -version = "1.0.0" - [dependencies.hammond-data] path = "../hammond-data" diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index b1e9679..09d2e44 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -219,7 +219,6 @@ mod tests { use hammond_data::Source; use hammond_data::feed::index; use hammond_data::dbqueries; - use diesel::associations::Identifiable; #[test] // This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit @@ -231,7 +230,7 @@ mod tests { // Create and index a source let mut source = Source::from_url(url).unwrap(); // Copy it's id - let sid = source.id().clone(); + let sid = source.id(); // Convert Source it into a Feed and index it let feed = source.into_feed(true).unwrap(); diff --git a/hammond-downloader/src/errors.rs b/hammond-downloader/src/errors.rs index 297d7eb..4b019c5 100644 --- a/hammond-downloader/src/errors.rs +++ b/hammond-downloader/src/errors.rs @@ -1,4 +1,3 @@ -use diesel::result; use reqwest; use hammond_data; use std::io; @@ -7,7 +6,6 @@ error_chain! { foreign_links { ReqError(reqwest::Error); IoError(io::Error); - DieselResultError(result::Error); DataError(hammond_data::errors::Error); } } diff --git a/hammond-downloader/src/lib.rs b/hammond-downloader/src/lib.rs index 9e57db8..197da0d 100644 --- a/hammond-downloader/src/lib.rs +++ b/hammond-downloader/src/lib.rs @@ -1,6 +1,5 @@ #![recursion_limit = "1024"] -extern crate diesel; #[macro_use] extern crate error_chain; extern crate glob; diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index db947d5..0dc8267 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -21,10 +21,6 @@ rayon = "0.9.0" regex = "0.2.3" send-cell = "0.1.2" -[dependencies.diesel] -features = ["sqlite"] -version = "1.0.0" - [dependencies.gtk] features = ["v3_22"] version = "0.3.0" diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 6e4c510..7f63acd 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -7,7 +7,6 @@ extern crate glib; extern crate gtk; extern crate chrono; -extern crate diesel; extern crate dissolve; extern crate hammond_data; extern crate hammond_downloader; diff --git a/hammond-gtk/src/manager.rs b/hammond-gtk/src/manager.rs index 2c426af..f6ba174 100644 --- a/hammond-gtk/src/manager.rs +++ b/hammond-gtk/src/manager.rs @@ -117,7 +117,6 @@ pub fn add(id: i32, directory: &str, sender: Sender) { #[cfg(test)] mod tests { use super::*; - use diesel::Identifiable; use hammond_data::database; use hammond_data::utils::get_download_folder; @@ -141,7 +140,7 @@ mod tests { // Create and index a source let mut source = Source::from_url(url).unwrap(); // Copy it's id - let sid = source.id().clone(); + let sid = source.id(); // Convert Source it into a Feed and index it let feed = source.into_feed(true).unwrap(); @@ -152,7 +151,7 @@ mod tests { // Get an episode let episode: Episode = { let con = database::connection(); - dbqueries::get_episode_from_pk(&*con.get().unwrap(), "e000: Hello, world!", *pd.id()) + dbqueries::get_episode_from_pk(&*con.get().unwrap(), "e000: Hello, world!", pd.id()) .unwrap() }; diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index c97aafa..1f55c5f 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -70,7 +70,6 @@ mod tests { use hammond_data::Source; use hammond_data::feed::index; use hammond_data::dbqueries; - use diesel::associations::Identifiable; use super::*; #[test] @@ -83,7 +82,7 @@ mod tests { // Create and index a source let mut source = Source::from_url(url).unwrap(); // Copy it's id - let sid = source.id().clone(); + let sid = source.id(); // Convert Source it into a Feed and index it let feed = source.into_feed(true).unwrap(); diff --git a/hammond-gtk/src/views/shows.rs b/hammond-gtk/src/views/shows.rs index 3a5b40b..72a5b1e 100644 --- a/hammond-gtk/src/views/shows.rs +++ b/hammond-gtk/src/views/shows.rs @@ -1,6 +1,5 @@ use gtk; use gtk::prelude::*; -use diesel::associations::Identifiable; use hammond_data::dbqueries; use hammond_data::Podcast; diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index 1b08638..c67db1d 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -1,6 +1,5 @@ use gtk::prelude::*; use gtk; -use diesel::Identifiable; use open; use dissolve;