Some renaming for consistency
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 2m17s
Cargo CI / Lint (pull_request) Successful in 1m17s

This commit is contained in:
Wojciech Kozlowski 2025-01-12 12:08:19 +01:00
parent 74b12e2ed0
commit 88c4d1b555
4 changed files with 35 additions and 35 deletions

View File

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

View File

@ -25,8 +25,8 @@ impl<'a> From<&'a Collection> for SerializeDatabase<'a> {
#[derive(Debug, Serialize, PartialEq, Eq)]
pub struct SerializeArtist<'a> {
pub name: &'a str,
pub mb_ref: SerializeMbRefOption<'a>,
pub sort: &'a Option<String>,
pub musicbrainz: SerializeMbRefOption<'a>,
pub properties: &'a HashMap<String, Vec<String>>,
pub albums: Vec<SerializeAlbum<'a>>,
}
@ -35,7 +35,7 @@ pub struct SerializeArtist<'a> {
pub struct SerializeAlbum<'a> {
pub title: &'a str,
pub lib_id: SerdeAlbumLibId,
pub musicbrainz: SerializeMbRefOption<'a>,
pub mb_ref: SerializeMbRefOption<'a>,
pub date: SerdeAlbumDate,
pub seq: u8,
pub primary_type: Option<SerdeAlbumPrimaryType>,
@ -75,7 +75,7 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> {
fn from(artist: &'a Artist) -> Self {
SerializeArtist {
name: &artist.meta.id.name,
musicbrainz: (&artist.meta.id.mb_ref).into(),
mb_ref: (&artist.meta.id.mb_ref).into(),
sort: &artist.meta.sort,
properties: &artist.meta.info.properties,
albums: artist.albums.iter().map(Into::into).collect(),
@ -88,7 +88,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
SerializeAlbum {
title: &album.meta.id.title,
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(),
seq: album.meta.seq.0,
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> {
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)",
);
Self::execute(
&mut stmt,
(
artist.name,
serde_json::to_string(&artist.mb_ref)?,
artist.sort,
serde_json::to_string(&artist.musicbrainz)?,
serde_json::to_string(&artist.properties)?,
),
)
@ -184,7 +184,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
while let Some(row) = Self::next_row(&mut rows)? {
artists.push(DeserializeArtist {
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)?,
properties: serde_json::from_str(&Self::get_value::<String>(row, 3)?)?,
albums: vec![],
@ -205,7 +205,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
(
album.title,
serde_json::to_string(&album.lib_id)?,
serde_json::to_string(&album.musicbrainz)?,
serde_json::to_string(&album.mb_ref)?,
artist_name,
album.date.0.year,
album.date.0.month,
@ -229,7 +229,7 @@ impl ISqlTransactionBackend for SqlTransactionSqliteBackend<'_> {
albums.push(DeserializeAlbum {
title: Self::get_value(row, 0)?,
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(
Self::get_value(row, 3)?,
Self::get_value(row, 4)?,

View File

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