diff --git a/src/external/database/mod.rs b/src/external/database/mod.rs index 72a8931..ceca477 100644 --- a/src/external/database/mod.rs +++ b/src/external/database/mod.rs @@ -3,5 +3,5 @@ pub mod json; #[cfg(feature = "database-sqlite")] pub mod sql; -#[cfg(feature = "database-json")] +#[cfg(any(feature = "database-json", feature = "database-sqlite"))] mod serde; diff --git a/src/external/database/serde/common.rs b/src/external/database/serde/common.rs index e46b3de..2dfea05 100644 --- a/src/external/database/serde/common.rs +++ b/src/external/database/serde/common.rs @@ -5,6 +5,8 @@ use crate::core::collection::{ musicbrainz::MbRefOption, }; +pub const V20250103: &str = "V20250103"; + #[derive(Debug, Deserialize, Serialize)] #[serde(remote = "AlbumLibId")] pub enum AlbumLibIdDef { diff --git a/src/external/database/sql/backend.rs b/src/external/database/sql/backend.rs index 41efd1c..3273751 100644 --- a/src/external/database/sql/backend.rs +++ b/src/external/database/sql/backend.rs @@ -1,4 +1,4 @@ -//! Module for storing MusicHoard data in a JSON file database. +//! Module for storing MusicHoard data in a SQLite database. use std::path::PathBuf; @@ -10,7 +10,7 @@ use crate::{ collection::album::AlbumDate, external::database::{ serde::{ - common::SerdeAlbumDate, + common::{SerdeAlbumDate, V20250103}, deserialize::{DeserializeAlbum, DeserializeArtist, DeserializeDatabase}, serialize::{SerializeAlbum, SerializeArtist, SerializeDatabase}, }, @@ -157,7 +157,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> { VALUES (?1, ?2)", )?; let version = match version { - SerializeDatabase::V20250103(_) => "V20250103", + SerializeDatabase::V20250103(_) => V20250103, }; Self::execute(&mut stmt, ("version", version)) } @@ -168,16 +168,11 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> { let mut rows = Self::query(&mut stmt, ())?; match Self::next_row(&mut rows)? { - Some(row) => { - let version: String = Self::get_value(row, 0)?; - match version.as_str() { - "V20250103" => Ok(DeserializeDatabase::V20250103(vec![])), - s => Err(Error::SerDeError(format!("unknown database version: {s}"))), - } - } - None => Err(Error::SerDeError(String::from( - "database version is missing", - ))), + Some(row) => match Self::get_value::(row, 0)?.as_str() { + V20250103 => Ok(DeserializeDatabase::V20250103(vec![])), + s => Err(Error::SerDeError(format!("unknown database version: {s}"))), + }, + None => Err(Error::SerDeError(String::from("missing database version"))), } } diff --git a/src/external/musicbrainz/api/mod.rs b/src/external/musicbrainz/api/mod.rs index 75c3c66..bc3cc60 100644 --- a/src/external/musicbrainz/api/mod.rs +++ b/src/external/musicbrainz/api/mod.rs @@ -227,7 +227,7 @@ impl<'de> Deserialize<'de> for SerdeMbid { } #[derive(Debug, Clone)] -pub struct SerdeAlbumDate(pub AlbumDate); +pub struct SerdeAlbumDate(AlbumDate); impl From for AlbumDate { fn from(value: SerdeAlbumDate) -> Self {