Skip to content

Commit

Permalink
store all tracks when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
pansen committed Aug 21, 2016
1 parent 38b8074 commit 74bfc9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ impl<'a> TrackManager<'a> {
hash: hash,
};

diesel::insert(&new_track).into(track::table)
.execute(self.conn)
.expect("Error saving new track");
match diesel::insert(&new_track).into(track::table)
.execute(self.conn) {
Err(why) => {
error!("failed saving new track: {:?}, {:?}", why, new_track);
},
Ok(t_) => {
info!("saved new track: {:?}", t_);
}
}

track_dsl.find(hash)
.get_result::<Track>(self.conn)
Expand Down
2 changes: 2 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::schema::track;
///
/// TODO amb: *attention* the `PRIMARY KEY` field must be the first in this struct
/// #[column_name(something)] will not work
#[derive(Debug)]
#[derive(Queryable)]
pub struct Track {
/// hash of the parsed file
Expand All @@ -18,6 +19,7 @@ pub struct Track {
}


#[derive(Debug)]
#[insertable_into(track)]
pub struct NewTrack<'a> {
pub hash: &'a str,
Expand Down
11 changes: 6 additions & 5 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ impl<'a> Scanner<'a> {
}
drop(tx);
for track_ in rx.iter() {
self.track_manager.create_track(&track_.path, &track_.album, &track_.title,
&track_.hash);
info!("{:?}", &track_.path);
warn!("{} - {} [{}]",
Green.paint(track_.album),
Green.paint(track_.title),
track_.hash,
Green.paint(track_.album.to_owned()),
Green.paint(track_.title.to_owned()),
track_.hash.to_owned(),
);
self.track_manager.create_track(&track_.path, &track_.album, &track_.title,
&track_.hash);
}
}

Expand Down

0 comments on commit 74bfc9d

Please sign in to comment.