Limit the information stored in the database #126
@ -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;
|
||||||
|
|
22
src/core/database/serde/mod.rs
Normal file
22
src/core/database/serde/mod.rs
Normal 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>>,
|
||||||
|
}
|
21
src/core/database/serde/serialize.rs
Normal file
21
src/core/database/serde/serialize.rs
Normal 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user