editor: Add basic work structure

This commit is contained in:
Elias Projahn 2024-06-01 13:49:13 +02:00
parent bdf8ed989d
commit 3eed04d04b
3 changed files with 51 additions and 6 deletions

View file

@ -38,6 +38,11 @@ pub fn connect(file_name: &str) -> Result<SqliteConnection> {
Ok(connection)
}
/// Generate a random string suitable as an item ID.
pub fn generate_id() -> String {
uuid::Uuid::new_v4().simple().to_string()
}
/// A single translated string value.
#[derive(Serialize, Deserialize, AsExpression, FromSqlRow, Clone, Default, Debug)]
#[diesel(sql_type = Text)]

View file

@ -21,7 +21,7 @@ pub struct Work {
}
// TODO: Handle part composers.
#[derive(Clone, Debug)]
#[derive(Default, Clone, Debug)]
pub struct WorkPart {
pub work_id: String,
pub level: u8,
@ -113,6 +113,13 @@ impl PartialEq for Composer {
}
}
impl Eq for WorkPart {}
impl PartialEq for WorkPart {
fn eq(&self, other: &Self) -> bool {
self.work_id == other.work_id
}
}
impl Work {
pub fn from_table(data: tables::Work, connection: &mut SqliteConnection) -> Result<Self> {
fn visit_children(