Limit the information stored in the database #126

Merged
wojtek merged 8 commits from 118---limit-the-information-stored-in-the-database into main 2024-02-10 20:23:10 +01:00
3 changed files with 47 additions and 38 deletions
Showing only changes of commit cc20c9f3dc - Show all commits

View File

@ -1,9 +1,3 @@
//! Helper module for backends that can use serde for (de)serialisation.
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use crate::{ use crate::{
collection::{ collection::{
self, self,
@ -11,21 +5,13 @@ use crate::{
}, },
core::{ core::{
collection::{artist::Artist, Collection}, collection::{artist::Artist, Collection},
database::LoadError, database::{
serde::{Database, DbArtist},
LoadError,
},
}, },
}; };
#[derive(Debug, Serialize, Deserialize)]
pub enum Database {
V20240210(Vec<DbArtist>),
}
impl From<&Collection> for Database {
fn from(collection: &Collection) -> Self {
Database::V20240210(collection.iter().map(|artist| artist.into()).collect())
}
}
impl TryFrom<Database> for Collection { impl TryFrom<Database> for Collection {
type Error = LoadError; type Error = LoadError;
@ -39,26 +25,6 @@ impl TryFrom<Database> for Collection {
} }
} }
// FIXME: try with references to original values.
#[derive(Debug, Serialize, Deserialize)]
pub struct DbArtist {
pub name: String,
pub sort: Option<String>,
pub musicbrainz: Option<String>,
pub properties: BTreeMap<String, Vec<String>>,
}
impl From<&Artist> for DbArtist {
fn from(artist: &Artist) -> Self {
DbArtist {
name: artist.id.name.clone(),
sort: artist.sort.clone().map(|id| id.name),
musicbrainz: artist.musicbrainz.clone().map(|mb| mb.as_ref().to_owned()),
properties: artist.properties.clone().into_iter().collect(),
}
}
}
impl TryFrom<DbArtist> for Artist { impl TryFrom<DbArtist> for Artist {
type Error = LoadError; type Error = LoadError;

View File

@ -0,0 +1,22 @@
//! Helper module for backends that can use serde for (de)serialisation.
pub mod deserialize;
pub mod serialize;
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub enum Database {
V20240210(Vec<DbArtist>),
}
// FIXME: try with references to original values.
#[derive(Debug, Serialize, Deserialize)]
pub struct DbArtist {
pub name: String,
pub sort: Option<String>,
pub musicbrainz: Option<String>,
pub properties: BTreeMap<String, Vec<String>>,
}

View File

@ -0,0 +1,21 @@
use crate::core::{
collection::{artist::Artist, Collection},
database::serde::{Database, DbArtist},
};
impl From<&Collection> for Database {
fn from(collection: &Collection) -> Self {
Database::V20240210(collection.iter().map(|artist| artist.into()).collect())
}
}
impl From<&Artist> for DbArtist {
fn from(artist: &Artist) -> Self {
DbArtist {
name: artist.id.name.clone(),
sort: artist.sort.clone().map(|id| id.name),
musicbrainz: artist.musicbrainz.clone().map(|mb| mb.as_ref().to_owned()),
properties: artist.properties.clone().into_iter().collect(),
}
}
}