Dbquerries: add EXIST querries for podcast and episode.
This commit is contained in:
parent
fa03c20b00
commit
978e5a61f6
@ -257,6 +257,33 @@ pub fn delete_podcast_episodes(con: &SqliteConnection, parent_id: i32) -> QueryR
|
|||||||
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(&*con)
|
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(&*con)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn podcast_exists(source_id_: i32) -> Result<bool> {
|
||||||
|
use schema::podcast::dsl::*;
|
||||||
|
use diesel::select;
|
||||||
|
use diesel::dsl::exists;
|
||||||
|
|
||||||
|
let db = connection();
|
||||||
|
let con = db.get()?;
|
||||||
|
|
||||||
|
select(exists(podcast.filter(source_id.eq(source_id_))))
|
||||||
|
.get_result(&*con)
|
||||||
|
.map_err(From::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
|
pub fn episode_exists(title_: &str, podcast_id_: i32) -> Result<bool> {
|
||||||
|
use schema::episode::dsl::*;
|
||||||
|
use diesel::select;
|
||||||
|
use diesel::dsl::exists;
|
||||||
|
|
||||||
|
let db = connection();
|
||||||
|
let con = db.get()?;
|
||||||
|
|
||||||
|
select(exists(episode.filter(podcast_id.eq(podcast_id_)).filter(title.eq(title_))))
|
||||||
|
.get_result(&*con)
|
||||||
|
.map_err(From::from)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize> {
|
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize> {
|
||||||
use schema::episode::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use diesel::result;
|
use diesel;
|
||||||
use diesel_migrations::RunMigrationsError;
|
use diesel_migrations::RunMigrationsError;
|
||||||
use rss;
|
use rss;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
@ -11,7 +11,7 @@ use std::io;
|
|||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
R2D2Error(r2d2::Error);
|
R2D2Error(r2d2::Error);
|
||||||
DieselResultError(result::Error);
|
DieselResultError(diesel::result::Error);
|
||||||
DieselMigrationError(RunMigrationsError);
|
DieselMigrationError(RunMigrationsError);
|
||||||
RSSError(rss::Error);
|
RSSError(rss::Error);
|
||||||
ReqError(reqwest::Error);
|
ReqError(reqwest::Error);
|
||||||
|
|||||||
@ -93,13 +93,9 @@ impl Feed {
|
|||||||
|
|
||||||
// This could also retrurn a FutureResult<Vec<FutureNewEpisode, Error>>, Error> Instead
|
// This could also retrurn a FutureResult<Vec<FutureNewEpisode, Error>>, Error> Instead
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn parse_channel_items_future(
|
fn parse_episodes_future(&self, pd: &Podcast) -> Box<Vec<FutureResult<NewEpisode, Error>>> {
|
||||||
&self,
|
let episodes = self.channel
|
||||||
pd: &Podcast,
|
.items()
|
||||||
) -> Box<Vec<FutureResult<NewEpisode, Error>>> {
|
|
||||||
let items = self.channel.items();
|
|
||||||
|
|
||||||
let episodes: Vec<_> = items
|
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|item| result(parser::new_episode(item, pd.id())))
|
.map(|item| result(parser::new_episode(item, pd.id())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user