Refactored dbquerries.

Refactored so dbquerries.rs module *should* be the only piece of code
that interacts with a Database connection. Insert stuff will be moved too.
This commit is contained in:
Jordan Petridis
2017-11-19 23:08:36 +02:00
parent 47b32ac000
commit beaeeffba8
3 changed files with 65 additions and 69 deletions
+3 -7
View File
@@ -67,7 +67,7 @@ impl<'a> NewEpisode<'a> {
let ep = {
// let tempdb = db.lock().unwrap();
// dbqueries::get_episode_from_uri(&tempdb, self.uri.unwrap())
dbqueries::get_episode_from_uri(con, self.uri.unwrap())
dbqueries::get_episode_from_uri(self.uri.unwrap())
};
match ep {
@@ -103,16 +103,12 @@ impl NewPodcast {
// Look out for when tryinto lands into stable.
pub fn into_podcast(self) -> Result<Podcast> {
self.index()?;
let tempdb = POOL.clone().get().unwrap();
Ok(dbqueries::get_podcast_from_title(&*tempdb, &self.title)?)
Ok(dbqueries::get_podcast_from_title(&self.title)?)
}
fn index(&self) -> QueryResult<()> {
use schema::podcast::dsl::*;
let pd = {
let tempdb = POOL.clone().get().unwrap();
dbqueries::get_podcast_from_title(&*tempdb, &self.title)
};
let pd = dbqueries::get_podcast_from_title(&self.title);
match pd {
Ok(foo) => if foo.link() != self.link {