From 494761beafd5e45a1158eae35f1841925625f023 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 18 Nov 2017 15:23:40 +0200 Subject: [PATCH] Removed id function from diesel models. It's automaticly declared upon derive identifiable, And there's no need to overwrite it. --- Cargo.lock | 8 +++++--- hammond-data/Cargo.toml | 4 +++- hammond-data/src/dbqueries.rs | 4 ++-- hammond-data/src/feed.rs | 5 +++-- hammond-data/src/models/queryables.rs | 12 ------------ hammond-gtk/Cargo.toml | 10 ++++++++++ hammond-gtk/src/main.rs | 2 +- hammond-gtk/src/views/podcasts_view.rs | 1 + hammond-gtk/src/widgets/episode.rs | 6 +++--- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b59315..e2a4e02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,7 @@ dependencies = [ [[package]] name = "diesel_codegen" version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/diesel-rs/diesel.git#07f80c3a0d07daa26efff3166fbf0297dc0f0a7b" dependencies = [ "diesel 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_infer_schema 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -548,7 +548,7 @@ version = "0.1.0" dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 0.16.0 (git+https://github.com/diesel-rs/diesel.git)", - "diesel_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_codegen 0.16.0 (git+https://github.com/diesel-rs/diesel.git)", "dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -581,6 +581,8 @@ dependencies = [ name = "hammond-gtk" version = "0.1.0" dependencies = [ + "diesel 0.16.0 (git+https://github.com/diesel-rs/diesel.git)", + "diesel_codegen 0.16.0 (git+https://github.com/diesel-rs/diesel.git)", "dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-pixbuf 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1570,7 +1572,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum derive_builder_core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eed37eae64daa5511467b1a55cebdf472deeaef108d22f62f25e8bbcaffd56ac" "checksum diesel 0.16.0 (git+https://github.com/diesel-rs/diesel.git)" = "" "checksum diesel 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "304226fa7a3982b0405f6bb95dd9c10c3e2000709f194038a60ec2c277150951" -"checksum diesel_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a42ca5c9b660add51d58bc5a50a87123380e1e458069c5504528a851ed7384" +"checksum diesel_codegen 0.16.0 (git+https://github.com/diesel-rs/diesel.git)" = "" "checksum diesel_infer_schema 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf1957ff5cd3b04772e43c162c2f69c2aa918080ff9b020276792d236be8be52" "checksum dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "898542be4716d992082c8e4fc331b792d626cfa71cb2b4790f828b9a8f921a90" "checksum dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d6f0e2bb24d163428d8031d3ebd2d2bd903ad933205a97d0f18c7c1aade380f3" diff --git a/hammond-data/Cargo.toml b/hammond-data/Cargo.toml index 4bf716e..ed09934 100644 --- a/hammond-data/Cargo.toml +++ b/hammond-data/Cargo.toml @@ -18,11 +18,13 @@ xdg = "2.1.0" [dependencies.diesel] features = ["sqlite"] +# version = "0.16.0" git = "https://github.com/diesel-rs/diesel.git" [dependencies.diesel_codegen] features = ["sqlite"] -version = "0.16.0" +# version = "0.16.0" +git = "https://github.com/diesel-rs/diesel.git" [dev-dependencies] rand = "0.3.18" diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index 075b7c8..679f5b8 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -127,8 +127,8 @@ pub fn remove_feed(db: &Database, pd: &Podcast) -> QueryResult { tempdb.transaction(|| -> QueryResult { delete_source(&tempdb, pd.source_id())?; - delete_podcast(&tempdb, pd.id())?; - delete_podcast_episodes(&tempdb, pd.id()) + delete_podcast(&tempdb, *pd.id())?; + delete_podcast_episodes(&tempdb, *pd.id()) }) } diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 987015c..56faf97 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -1,4 +1,5 @@ use rayon::prelude::*; +use diesel::Identifiable; use rss; @@ -38,7 +39,7 @@ impl Feed { } fn index_channel(&self, db: &Database) -> Result { - let pd = parser::new_podcast(&self.channel, self.source.id()); + let pd = parser::new_podcast(&self.channel, *self.source.id()); // Convert NewPodcast to Podcast pd.into_podcast(db) } @@ -49,7 +50,7 @@ impl Feed { fn index_channel_items(&self, db: &Database, pd: &Podcast) -> Result<()> { let it = self.channel.items(); let episodes: Vec<_> = it.par_iter() - .map(|x| parser::new_episode(x, pd.id())) + .map(|x| parser::new_episode(x, *pd.id())) .collect(); episodes.into_par_iter().for_each(|x| { diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 8430258..be31df6 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -39,10 +39,6 @@ pub struct Episode { } impl Episode { - pub fn id(&self) -> i32 { - self.id - } - pub fn title(&self) -> Option<&str> { self.title.as_ref().map(|s| s.as_str()) } @@ -173,10 +169,6 @@ impl From for Podcast { } impl Podcast { - pub fn id(&self) -> i32 { - self.id - } - pub fn source_id(&self) -> i32 { self.source_id } @@ -251,10 +243,6 @@ pub struct Source { } impl<'a> Source { - pub fn id(&self) -> i32 { - self.id - } - pub fn uri(&self) -> &str { &self.uri } diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 13e95ef..4a08df9 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -20,6 +20,16 @@ rayon = "0.9.0" features = ["v3_22"] version = "0.2.0" +[dependencies.diesel] +features = ["sqlite"] +# version = "0.16.0" +git = "https://github.com/diesel-rs/diesel.git" + +[dependencies.diesel_codegen] +features = ["sqlite"] +# version = "0.16.0" +git = "https://github.com/diesel-rs/diesel.git" + [dependencies.hammond-data] path = "../hammond-data" diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 6ca4ee4..046945e 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -4,7 +4,7 @@ extern crate gio; extern crate glib; extern crate gtk; -// extern crate diesel; +extern crate diesel; extern crate dissolve; extern crate hammond_data; extern crate hammond_downloader; diff --git a/hammond-gtk/src/views/podcasts_view.rs b/hammond-gtk/src/views/podcasts_view.rs index 5f73684..9bfcaca 100644 --- a/hammond-gtk/src/views/podcasts_view.rs +++ b/hammond-gtk/src/views/podcasts_view.rs @@ -1,6 +1,7 @@ use gtk; use gtk::prelude::*; use gdk_pixbuf::Pixbuf; +use diesel::associations::Identifiable; use hammond_data::dbqueries; use hammond_data::models::Podcast; diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index b0faf40..432d1a3 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -1,4 +1,3 @@ - use open; use hammond_data::dbqueries; use hammond_data::models::{Episode, Podcast}; @@ -8,6 +7,7 @@ use hammond_data::utils::*; use hammond_data::errors::*; use dissolve::strip_html_tags; +use diesel::associations::Identifiable; use std::thread; use std::cell::RefCell; @@ -71,7 +71,7 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk:: play_button.connect_clicked( clone!(db, episode, played_button, unplayed_button => move |_| { - on_play_bttn_clicked(&db, episode.id()); + on_play_bttn_clicked(&db, *episode.id()); let _ = set_played_now(&db, &mut episode.clone()); played_button.hide(); unplayed_button.show(); @@ -80,7 +80,7 @@ fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk:: delete_button.connect_clicked( clone!(episode, db, play_button, download_button => move |del| { - on_delete_bttn_clicked(&db, episode.id()); + on_delete_bttn_clicked(&db, *episode.id()); del.hide(); play_button.hide(); download_button.show();