Clean up some code
This commit is contained in:
parent
4a59611311
commit
8c83c6fac6
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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::<String>(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"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ impl<'de> Deserialize<'de> for SerdeMbid {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SerdeAlbumDate(pub AlbumDate);
|
||||
pub struct SerdeAlbumDate(AlbumDate);
|
||||
|
||||
impl From<SerdeAlbumDate> for AlbumDate {
|
||||
fn from(value: SerdeAlbumDate) -> Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user