Remove database-json #267

Merged
wojtek merged 7 commits from 248---replace-json-file-as-a-database-with-sqlite into main 2025-01-12 12:18:25 +01:00
4 changed files with 35 additions and 35 deletions
Showing only changes of commit 88c4d1b555 - Show all commits

View File

@ -35,7 +35,7 @@ impl From<DeserializeDatabase> for Collection {
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct DeserializeArtist { pub struct DeserializeArtist {
pub name: String, pub name: String,
pub musicbrainz: DeserializeMbRefOption, pub mb_ref: DeserializeMbRefOption,
pub sort: Option<String>, pub sort: Option<String>,
pub properties: HashMap<String, Vec<String>>, pub properties: HashMap<String, Vec<String>>,
pub albums: Vec<DeserializeAlbum>, pub albums: Vec<DeserializeAlbum>,
@ -45,7 +45,7 @@ pub struct DeserializeArtist {
pub struct DeserializeAlbum { pub struct DeserializeAlbum {
pub title: String, pub title: String,
pub lib_id: SerdeAlbumLibId, pub lib_id: SerdeAlbumLibId,
pub musicbrainz: DeserializeMbRefOption, pub mb_ref: DeserializeMbRefOption,
pub date: SerdeAlbumDate, pub date: SerdeAlbumDate,
pub seq: u8, pub seq: u8,
pub primary_type: Option<SerdeAlbumPrimaryType>, pub primary_type: Option<SerdeAlbumPrimaryType>,
@ -120,7 +120,7 @@ impl From<DeserializeArtist> for Artist {
meta: ArtistMeta { meta: ArtistMeta {
id: ArtistId { id: ArtistId {
name: artist.name, name: artist.name,
mb_ref: artist.musicbrainz.into(), mb_ref: artist.mb_ref.into(),
}, },
sort: artist.sort, sort: artist.sort,
info: ArtistInfo { info: ArtistInfo {
@ -139,7 +139,7 @@ impl From<DeserializeAlbum> for Album {
id: AlbumId { id: AlbumId {
title: album.title, title: album.title,
lib_id: album.lib_id.into(), lib_id: album.lib_id.into(),
mb_ref: album.musicbrainz.into(), mb_ref: album.mb_ref.into(),
}, },
date: album.date.into(), date: album.date.into(),
seq: AlbumSeq(album.seq), seq: AlbumSeq(album.seq),

View File

@ -25,8 +25,8 @@ impl<'a> From<&'a Collection> for SerializeDatabase<'a> {
#[derive(Debug, Serialize, PartialEq, Eq)] #[derive(Debug, Serialize, PartialEq, Eq)]
pub struct SerializeArtist<'a> { pub struct SerializeArtist<'a> {
pub name: &'a str, pub name: &'a str,
pub mb_ref: SerializeMbRefOption<'a>,
pub sort: &'a Option<String>, pub sort: &'a Option<String>,
pub musicbrainz: SerializeMbRefOption<'a>,
pub properties: &'a HashMap<String, Vec<String>>, pub properties: &'a HashMap<String, Vec<String>>,
pub albums: Vec<SerializeAlbum<'a>>, pub albums: Vec<SerializeAlbum<'a>>,
} }
@ -35,7 +35,7 @@ pub struct SerializeArtist<'a> {
pub struct SerializeAlbum<'a> { pub struct SerializeAlbum<'a> {
pub title: &'a str, pub title: &'a str,
pub lib_id: SerdeAlbumLibId, pub lib_id: SerdeAlbumLibId,
pub musicbrainz: SerializeMbRefOption<'a>, pub mb_ref: SerializeMbRefOption<'a>,
pub date: SerdeAlbumDate, pub date: SerdeAlbumDate,
pub seq: u8, pub seq: u8,
pub primary_type: Option<SerdeAlbumPrimaryType>, pub primary_type: Option<SerdeAlbumPrimaryType>,
@ -75,7 +75,7 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> {
fn from(artist: &'a Artist) -> Self { fn from(artist: &'a Artist) -> Self {
SerializeArtist { SerializeArtist {
name: &artist.meta.id.name, name: &artist.meta.id.name,
musicbrainz: (&artist.meta.id.mb_ref).into(), mb_ref: (&artist.meta.id.mb_ref).into(),
sort: &artist.meta.sort, sort: &artist.meta.sort,
properties: &artist.meta.info.properties, properties: &artist.meta.info.properties,
albums: artist.albums.iter().map(Into::into).collect(), albums: artist.albums.iter().map(Into::into).collect(),
@ -88,7 +88,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
SerializeAlbum { SerializeAlbum {
title: &album.meta.id.title, title: &album.meta.id.title,
lib_id: album.meta.id.lib_id.into(), lib_id: album.meta.id.lib_id.into(),
musicbrainz: (&album.meta.id.mb_ref).into(), mb_ref: (&album.meta.id.mb_ref).into(),
date: album.meta.date.into(), date: album.meta.date.into(),
seq: album.meta.seq.0, seq: album.meta.seq.0,
primary_type: album.meta.info.primary_type.map(Into::into), primary_type: album.meta.info.primary_type.map(Into::into),

View File

@ -162,15 +162,15 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
fn insert_artist(&self, artist: &SerializeArtist<'_>) -> Result<(), Error> { fn insert_artist(&self, artist: &SerializeArtist<'_>) -> Result<(), Error> {
let mut stmt = self.prepare_cached( let mut stmt = self.prepare_cached(
"INSERT INTO artists (name, sort, mbid, properties) "INSERT INTO artists (name, mbid, sort, properties)
VALUES (?1, ?2, ?3, ?4)", VALUES (?1, ?2, ?3, ?4)",
); );
Self::execute( Self::execute(
&mut stmt, &mut stmt,
( (
artist.name, artist.name,
serde_json::to_string(&artist.mb_ref)?,
artist.sort, artist.sort,
serde_json::to_string(&artist.musicbrainz)?,
serde_json::to_string(&artist.properties)?, serde_json::to_string(&artist.properties)?,
), ),
) )
@ -184,7 +184,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
while let Some(row) = Self::next_row(&mut rows)? { while let Some(row) = Self::next_row(&mut rows)? {
artists.push(DeserializeArtist { artists.push(DeserializeArtist {
name: Self::get_value(row, 0)?, name: Self::get_value(row, 0)?,
musicbrainz: serde_json::from_str(&Self::get_value::<String>(row, 1)?)?, mb_ref: serde_json::from_str(&Self::get_value::<String>(row, 1)?)?,
sort: Self::get_value(row, 2)?, sort: Self::get_value(row, 2)?,
properties: serde_json::from_str(&Self::get_value::<String>(row, 3)?)?, properties: serde_json::from_str(&Self::get_value::<String>(row, 3)?)?,
albums: vec![], albums: vec![],
@ -205,7 +205,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
( (
album.title, album.title,
serde_json::to_string(&album.lib_id)?, serde_json::to_string(&album.lib_id)?,
serde_json::to_string(&album.musicbrainz)?, serde_json::to_string(&album.mb_ref)?,
artist_name, artist_name,
album.date.0.year, album.date.0.year,
album.date.0.month, album.date.0.month,
@ -229,7 +229,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
albums.push(DeserializeAlbum { albums.push(DeserializeAlbum {
title: Self::get_value(row, 0)?, title: Self::get_value(row, 0)?,
lib_id: serde_json::from_str(&Self::get_value::<String>(row, 1)?)?, lib_id: serde_json::from_str(&Self::get_value::<String>(row, 1)?)?,
musicbrainz: serde_json::from_str(&Self::get_value::<String>(row, 2)?)?, mb_ref: serde_json::from_str(&Self::get_value::<String>(row, 2)?)?,
date: SerdeAlbumDate(AlbumDate::new( date: SerdeAlbumDate(AlbumDate::new(
Self::get_value(row, 3)?, Self::get_value(row, 3)?,
Self::get_value(row, 4)?, Self::get_value(row, 4)?,

View File

@ -21,10 +21,10 @@ pub static DATABASE_SQL_ARTISTS: Lazy<Vec<DeserializeArtist>> = Lazy::new(|| {
vec![ vec![
DeserializeArtist { DeserializeArtist {
name: String::from("Album_Artist A"), name: String::from("Album_Artist A"),
sort: None, mb_ref: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
musicbrainz: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
"00000000-0000-0000-0000-000000000000".try_into().unwrap(), "00000000-0000-0000-0000-000000000000".try_into().unwrap(),
))), ))),
sort: None,
properties: HashMap::from([ properties: HashMap::from([
( (
String::from("MusicButler"), String::from("MusicButler"),
@ -43,10 +43,10 @@ pub static DATABASE_SQL_ARTISTS: Lazy<Vec<DeserializeArtist>> = Lazy::new(|| {
}, },
DeserializeArtist { DeserializeArtist {
name: String::from("Album_Artist B"), name: String::from("Album_Artist B"),
sort: None, mb_ref: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
musicbrainz: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
"11111111-1111-1111-1111-111111111111".try_into().unwrap(), "11111111-1111-1111-1111-111111111111".try_into().unwrap(),
))), ))),
sort: None,
properties: HashMap::from([ properties: HashMap::from([
(String::from("MusicButler"), vec![ (String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/111111111"), String::from("https://www.musicbutler.io/artist-page/111111111"),
@ -65,15 +65,15 @@ pub static DATABASE_SQL_ARTISTS: Lazy<Vec<DeserializeArtist>> = Lazy::new(|| {
}, },
DeserializeArtist { DeserializeArtist {
name: String::from("The Album_Artist C"), name: String::from("The Album_Artist C"),
mb_ref: DeserializeMbRefOption(MbRefOption::CannotHaveMbid),
sort: Some(String::from("Album_Artist C, The")), sort: Some(String::from("Album_Artist C, The")),
musicbrainz: DeserializeMbRefOption(MbRefOption::CannotHaveMbid),
properties: HashMap::new(), properties: HashMap::new(),
albums: vec![], albums: vec![],
}, },
DeserializeArtist { DeserializeArtist {
name: String::from("Album_Artist D"), name: String::from("Album_Artist D"),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
sort: None, sort: None,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
properties: HashMap::new(), properties: HashMap::new(),
albums: vec![], albums: vec![],
}, },
@ -88,20 +88,20 @@ pub static DATABASE_SQL_ALBUMS: Lazy<HashMap<String, Vec<DeserializeAlbum>>> = L
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title a.a"), title: String::from("album_title a.a"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(1)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(1)),
date: SerdeAlbumDate(AlbumDate::new(Some(1998), None, None)), mb_ref: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
seq: 1,
musicbrainz: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
"00000000-0000-0000-0000-000000000000".try_into().unwrap(), "00000000-0000-0000-0000-000000000000".try_into().unwrap(),
))), ))),
date: SerdeAlbumDate(AlbumDate::new(Some(1998), None, None)),
seq: 1,
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title a.b"), title: String::from("album_title a.b"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(2)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(2)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(2015), Some(4), None)), date: SerdeAlbumDate(AlbumDate::new(Some(2015), Some(4), None)),
seq: 1, seq: 1,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
@ -113,40 +113,40 @@ pub static DATABASE_SQL_ALBUMS: Lazy<HashMap<String, Vec<DeserializeAlbum>>> = L
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title b.a"), title: String::from("album_title b.a"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(3)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(3)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(2003), Some(6), Some(6))), date: SerdeAlbumDate(AlbumDate::new(Some(2003), Some(6), Some(6))),
seq: 1, seq: 1,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title b.b"), title: String::from("album_title b.b"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(4)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(4)),
date: SerdeAlbumDate(AlbumDate::new(Some(2008), None, None)), mb_ref: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
seq: 3,
musicbrainz: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
"11111111-1111-1111-1111-111111111111".try_into().unwrap(), "11111111-1111-1111-1111-111111111111".try_into().unwrap(),
))), ))),
date: SerdeAlbumDate(AlbumDate::new(Some(2008), None, None)),
seq: 3,
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title b.c"), title: String::from("album_title b.c"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(5)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(5)),
date: SerdeAlbumDate(AlbumDate::new(Some(2009), None, None)), mb_ref: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
seq: 2,
musicbrainz: DeserializeMbRefOption(MbRefOption::Some(DeserializeMbid(
"11111111-1111-1111-1111-111111111112".try_into().unwrap(), "11111111-1111-1111-1111-111111111112".try_into().unwrap(),
))), ))),
date: SerdeAlbumDate(AlbumDate::new(Some(2009), None, None)),
seq: 2,
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title b.d"), title: String::from("album_title b.d"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(6)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(6)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(2015), None, None)), date: SerdeAlbumDate(AlbumDate::new(Some(2015), None, None)),
seq: 4, seq: 4,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
@ -158,18 +158,18 @@ pub static DATABASE_SQL_ALBUMS: Lazy<HashMap<String, Vec<DeserializeAlbum>>> = L
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title c.a"), title: String::from("album_title c.a"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(7)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(7)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(1985), None, None)), date: SerdeAlbumDate(AlbumDate::new(Some(1985), None, None)),
seq: 0, seq: 0,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title c.b"), title: String::from("album_title c.b"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(8)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(8)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(2018), None, None)), date: SerdeAlbumDate(AlbumDate::new(Some(2018), None, None)),
seq: 0, seq: 0,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
@ -181,9 +181,9 @@ pub static DATABASE_SQL_ALBUMS: Lazy<HashMap<String, Vec<DeserializeAlbum>>> = L
DeserializeAlbum { DeserializeAlbum {
title: String::from("album_title d.a"), title: String::from("album_title d.a"),
lib_id: SerdeAlbumLibId(AlbumLibId::Value(9)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(9)),
mb_ref: DeserializeMbRefOption(MbRefOption::None),
date: SerdeAlbumDate(AlbumDate::new(Some(1995), None, None)), date: SerdeAlbumDate(AlbumDate::new(Some(1995), None, None)),
seq: 0, seq: 0,
musicbrainz: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },
@ -192,7 +192,7 @@ pub static DATABASE_SQL_ALBUMS: Lazy<HashMap<String, Vec<DeserializeAlbum>>> = L
lib_id: SerdeAlbumLibId(AlbumLibId::Value(10)), lib_id: SerdeAlbumLibId(AlbumLibId::Value(10)),
date: SerdeAlbumDate(AlbumDate::new(Some(2028), None, None)), date: SerdeAlbumDate(AlbumDate::new(Some(2028), None, None)),
seq: 0, seq: 0,
musicbrainz: DeserializeMbRefOption(MbRefOption::None), mb_ref: DeserializeMbRefOption(MbRefOption::None),
primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)), primary_type: Some(SerdeAlbumPrimaryType(AlbumPrimaryType::Album)),
secondary_types: vec![], secondary_types: vec![],
}, },