From e7ef07fe6aed596660fe7313375d81a0a8bc0e76 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sat, 1 Jul 2017 11:56:51 -0700 Subject: [PATCH] Moved index structs out of models module --- src/db/index.rs | 42 +++++++++++++++++++++++++++++++++++++----- src/db/mod.rs | 1 + src/db/models.rs | 38 -------------------------------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/db/index.rs b/src/db/index.rs index 0fb651c..c5d2f77 100644 --- a/src/db/index.rs +++ b/src/db/index.rs @@ -11,7 +11,7 @@ use std::time; use config::UserConfig; use db::DB; -use db::models::*; +use db::models::MiscSettings; use db::schema::*; use errors::*; use metadata; @@ -19,6 +19,42 @@ use metadata; const INDEX_BUILDING_INSERT_BUFFER_SIZE: usize = 1000; // Insertions in each transaction const INDEX_BUILDING_CLEAN_BUFFER_SIZE: usize = 500; // Insertions in each transaction +#[derive(Debug, Queryable, Serialize)] +pub struct Song { + #[serde(skip_serializing)] + id: i32, + pub path: String, + #[serde(skip_serializing)] + pub parent: String, + pub track_number: Option, + pub disc_number: Option, + pub title: Option, + pub artist: Option, + pub album_artist: Option, + pub year: Option, + pub album: Option, + pub artwork: Option, +} + +#[derive(Debug, Queryable, Serialize)] +pub struct Directory { + #[serde(skip_serializing)] + id: i32, + pub path: String, + #[serde(skip_serializing)] + pub parent: Option, + pub artist: Option, + pub year: Option, + pub album: Option, + pub artwork: Option, + pub date_added: i32, +} + +#[derive(Debug, Serialize)] +pub enum CollectionFile { + Directory(Directory), + Song(Song), +} #[derive(Debug, Insertable)] #[table_name="songs"] @@ -383,8 +419,6 @@ fn _get_test_db(name: &str) -> DB { #[test] fn test_populate() { - use db::models::*; - let db = _get_test_db("populate.sqlite"); update(&db).unwrap(); update(&db).unwrap(); // Check that subsequent updates don't run into conflicts @@ -400,8 +434,6 @@ fn test_populate() { #[test] fn test_metadata() { - use db::models::*; - let mut target = PathBuf::new(); target.push("test"); target.push("collection"); diff --git a/src/db/mod.rs b/src/db/mod.rs index 538a020..50d5eff 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -18,6 +18,7 @@ mod index; mod models; mod schema; +use self::index::{CollectionFile, Directory, Song}; pub use self::schema::*; pub use self::models::*; diff --git a/src/db/models.rs b/src/db/models.rs index 9d27a28..fb61bc5 100644 --- a/src/db/models.rs +++ b/src/db/models.rs @@ -1,41 +1,3 @@ -// Collection content -#[derive(Debug, Queryable, Serialize)] -pub struct Song { - #[serde(skip_serializing)] - id: i32, - pub path: String, - #[serde(skip_serializing)] - pub parent: String, - pub track_number: Option, - pub disc_number: Option, - pub title: Option, - pub artist: Option, - pub album_artist: Option, - pub year: Option, - pub album: Option, - pub artwork: Option, -} - -#[derive(Debug, Queryable, Serialize)] -pub struct Directory { - #[serde(skip_serializing)] - id: i32, - pub path: String, - #[serde(skip_serializing)] - pub parent: Option, - pub artist: Option, - pub year: Option, - pub album: Option, - pub artwork: Option, - pub date_added: i32, -} - -#[derive(Debug, Serialize)] -pub enum CollectionFile { - Directory(Directory), - Song(Song), -} - // Misc Settings #[derive(Debug, Queryable)] pub struct MiscSettings {