From 37a408e58a6db275d6b9d7f49e2796aab028cf08 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 19 Apr 2018 14:45:00 +0300 Subject: [PATCH] dbquerries: Fix the is_populated() querries. Thanks a lot to the diesel gittrer channel! --- hammond-data/src/dbqueries.rs | 41 ++++++----------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index a5d8e18..38b9a4b 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -5,6 +5,7 @@ use diesel::prelude::*; use diesel; use diesel::dsl::exists; +use diesel::query_builder::AsQuery; use diesel::select; use database::connection; @@ -349,59 +350,31 @@ pub(crate) fn episode_exists(title_: &str, podcast_id_: i32) -> Result Result { use schema::episode::dsl::*; let db = connection(); let con = db.get()?; - // FIXME - // select(exists(select(episode))) - // .get_result(&con) - // .map_err(From::from) - - episode - .count() + select(exists(episode.as_query())) .get_result(&con) - // FIXME: fix the diesel querry - .map(|b: i64| { - if b == 0 { - false - } else { - true - } - }) .map_err(From::from) } -/// Check `episode` table empty +/// Check if the `podcast` table contains any rows /// -// FIXME: Return true if `episode` table is populated. +/// Return true if `podcast table is populated. pub fn is_podcasts_populated() -> Result { use schema::podcast::dsl::*; let db = connection(); let con = db.get()?; - // FIXME - // select(exists(select(podcast))) - // .get_result(&con) - // .map_err(From::from) - - podcast - .count() + select(exists(podcast.as_query())) .get_result(&con) - // FIXME: fix the diesel querry - .map(|b: i64| { - if b == 0 { - false - } else { - true - } - }) .map_err(From::from) }