dbquerries: Fix the is_populated() querries.
Thanks a lot to the diesel gittrer channel!
This commit is contained in:
parent
736a993284
commit
37a408e58a
@ -5,6 +5,7 @@ use diesel::prelude::*;
|
|||||||
|
|
||||||
use diesel;
|
use diesel;
|
||||||
use diesel::dsl::exists;
|
use diesel::dsl::exists;
|
||||||
|
use diesel::query_builder::AsQuery;
|
||||||
use diesel::select;
|
use diesel::select;
|
||||||
|
|
||||||
use database::connection;
|
use database::connection;
|
||||||
@ -349,59 +350,31 @@ pub(crate) fn episode_exists(title_: &str, podcast_id_: i32) -> Result<bool, Dat
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check `episode` table empty
|
/// Check if the `episode table contains any rows
|
||||||
///
|
///
|
||||||
// FIXME: Return true if `episode` table is populated.
|
/// Return true if `episode` table is populated.
|
||||||
pub fn is_episodes_populated() -> Result<bool, DataError> {
|
pub fn is_episodes_populated() -> Result<bool, DataError> {
|
||||||
use schema::episode::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
// FIXME
|
select(exists(episode.as_query()))
|
||||||
// select(exists(select(episode)))
|
|
||||||
// .get_result(&con)
|
|
||||||
// .map_err(From::from)
|
|
||||||
|
|
||||||
episode
|
|
||||||
.count()
|
|
||||||
.get_result(&con)
|
.get_result(&con)
|
||||||
// FIXME: fix the diesel querry
|
|
||||||
.map(|b: i64| {
|
|
||||||
if b == 0 {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map_err(From::from)
|
.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<bool, DataError> {
|
pub fn is_podcasts_populated() -> Result<bool, DataError> {
|
||||||
use schema::podcast::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
// FIXME
|
select(exists(podcast.as_query()))
|
||||||
// select(exists(select(podcast)))
|
|
||||||
// .get_result(&con)
|
|
||||||
// .map_err(From::from)
|
|
||||||
|
|
||||||
podcast
|
|
||||||
.count()
|
|
||||||
.get_result(&con)
|
.get_result(&con)
|
||||||
// FIXME: fix the diesel querry
|
|
||||||
.map(|b: i64| {
|
|
||||||
if b == 0 {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user