diff --git a/musicus/Cargo.toml b/musicus/Cargo.toml index e84df8a..5eb4561 100644 --- a/musicus/Cargo.toml +++ b/musicus/Cargo.toml @@ -25,3 +25,4 @@ rand = "0.7.3" secret-service = "1.1.1" serde = { version = "1.0.117", features = ["derive"] } serde_json = "1.0.59" +uuid = { version = "0.8", features = ["v4"] } diff --git a/musicus/migrations/2020-09-27-201047_initial_schema/up.sql b/musicus/migrations/2020-09-27-201047_initial_schema/up.sql index 7d30680..27b97a6 100644 --- a/musicus/migrations/2020-09-27-201047_initial_schema/up.sql +++ b/musicus/migrations/2020-09-27-201047_initial_schema/up.sql @@ -1,64 +1,64 @@ CREATE TABLE persons ( - id BIGINT NOT NULL PRIMARY KEY, + id TEXT NOT NULL PRIMARY KEY, first_name TEXT NOT NULL, last_name TEXT NOT NULL ); CREATE TABLE instruments ( - id BIGINT NOT NULL PRIMARY KEY, + id TEXT NOT NULL PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE works ( - id BIGINT NOT NULL PRIMARY KEY, - composer BIGINT NOT NULL REFERENCES persons(id), + id TEXT NOT NULL PRIMARY KEY, + composer TEXT NOT NULL REFERENCES persons(id), title TEXT NOT NULL ); CREATE TABLE instrumentations ( id BIGINT NOT NULL PRIMARY KEY, - work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE, - instrument BIGINT NOT NULL REFERENCES instruments(id) ON DELETE CASCADE + work TEXT NOT NULL REFERENCES works(id) ON DELETE CASCADE, + instrument TEXT NOT NULL REFERENCES instruments(id) ON DELETE CASCADE ); CREATE TABLE work_parts ( id BIGINT NOT NULL PRIMARY KEY, - work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE, + work TEXT NOT NULL REFERENCES works(id) ON DELETE CASCADE, part_index BIGINT NOT NULL, title TEXT NOT NULL, - composer BIGINT REFERENCES persons(id) + composer TEXT REFERENCES persons(id) ); CREATE TABLE work_sections ( id BIGINT NOT NULL PRIMARY KEY, - work BIGINT NOT NULL REFERENCES works(id) ON DELETE CASCADE, + work TEXT NOT NULL REFERENCES works(id) ON DELETE CASCADE, title TEXT NOT NULL, before_index BIGINT NOT NULL ); CREATE TABLE ensembles ( - id BIGINT NOT NULL PRIMARY KEY, + id TEXT NOT NULL PRIMARY KEY, name TEXT NOT NULL ); CREATE TABLE recordings ( - id BIGINT NOT NULL PRIMARY KEY, - work BIGINT NOT NULL REFERENCES works(id), + id TEXT NOT NULL PRIMARY KEY, + work TEXT NOT NULL REFERENCES works(id), comment TEXT NOT NULL ); CREATE TABLE performances ( id BIGINT NOT NULL PRIMARY KEY, - recording BIGINT NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, - person BIGINT REFERENCES persons(id), - ensemble BIGINT REFERENCES ensembles(id), - role BIGINT REFERENCES instruments(id) + recording TEXT NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + person TEXT REFERENCES persons(id), + ensemble TEXT REFERENCES ensembles(id), + role TEXT REFERENCES instruments(id) ); CREATE TABLE tracks ( id BIGINT NOT NULL PRIMARY KEY, file_name TEXT NOT NULL, - recording BIGINT NOT NULL REFERENCES recordings(id), + recording TEXT NOT NULL REFERENCES recordings(id), track_index INTEGER NOT NULL, work_parts TEXT NOT NULL ); \ No newline at end of file diff --git a/musicus/src/database/ensembles.rs b/musicus/src/database/ensembles.rs index 1b51deb..62475a3 100644 --- a/musicus/src/database/ensembles.rs +++ b/musicus/src/database/ensembles.rs @@ -1,57 +1,25 @@ use super::schema::ensembles; use super::Database; -use anyhow::{Error, Result}; +use anyhow::Result; use diesel::prelude::*; -use diesel::{Insertable, Queryable}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; - -/// Database table data for an ensemble. -#[derive(Insertable, Queryable, Debug, Clone)] -#[table_name = "ensembles"] -struct EnsembleRow { - pub id: i64, - pub name: String, -} - -impl From for EnsembleRow { - fn from(ensemble: Ensemble) -> Self { - EnsembleRow { - id: ensemble.id as i64, - name: ensemble.name, - } - } -} /// An ensemble that takes part in recordings. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Insertable, Queryable, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Ensemble { - pub id: u32, + pub id: String, pub name: String, } -impl TryFrom for Ensemble { - type Error = Error; - fn try_from(row: EnsembleRow) -> Result { - let ensemble = Ensemble { - id: row.id.try_into()?, - name: row.name, - }; - - Ok(ensemble) - } -} - impl Database { /// Update an existing ensemble or insert a new one. pub fn update_ensemble(&self, ensemble: Ensemble) -> Result<()> { self.defer_foreign_keys()?; self.connection.transaction(|| { - let row: EnsembleRow = ensemble.into(); diesel::replace_into(ensembles::table) - .values(row) + .values(ensemble) .execute(&self.connection) })?; @@ -59,37 +27,26 @@ impl Database { } /// Get an existing ensemble. - pub fn get_ensemble(&self, id: u32) -> Result> { - let row = ensembles::table - .filter(ensembles::id.eq(id as i64)) - .load::(&self.connection)? - .first() - .cloned(); - - let ensemble = match row { - Some(row) => Some(row.try_into()?), - None => None, - }; + pub fn get_ensemble(&self, id: &str) -> Result> { + let ensemble = ensembles::table + .filter(ensembles::id.eq(id)) + .load::(&self.connection)? + .into_iter() + .next(); Ok(ensemble) } /// Delete an existing ensemble. - pub fn delete_ensemble(&self, id: u32) -> Result<()> { - diesel::delete(ensembles::table.filter(ensembles::id.eq(id as i64))) - .execute(&self.connection)?; + pub fn delete_ensemble(&self, id: &str) -> Result<()> { + diesel::delete(ensembles::table.filter(ensembles::id.eq(id))).execute(&self.connection)?; Ok(()) } /// Get all existing ensembles. pub fn get_ensembles(&self) -> Result> { - let mut ensembles = Vec::::new(); - - let rows = ensembles::table.load::(&self.connection)?; - for row in rows { - ensembles.push(row.try_into()?); - } + let ensembles = ensembles::table.load::(&self.connection)?; Ok(ensembles) } diff --git a/musicus/src/database/instruments.rs b/musicus/src/database/instruments.rs index 83e0905..1083a30 100644 --- a/musicus/src/database/instruments.rs +++ b/musicus/src/database/instruments.rs @@ -1,57 +1,25 @@ use super::schema::instruments; use super::Database; -use anyhow::{Error, Result}; +use anyhow::Result; use diesel::prelude::*; -use diesel::{Insertable, Queryable}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; - -/// Table row data for an instrument. -#[derive(Insertable, Queryable, Debug, Clone)] -#[table_name = "instruments"] -struct InstrumentRow { - pub id: i64, - pub name: String, -} - -impl From for InstrumentRow { - fn from(instrument: Instrument) -> Self { - InstrumentRow { - id: instrument.id as i64, - name: instrument.name, - } - } -} /// An instrument or any other possible role within a recording. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Insertable, Queryable, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Instrument { - pub id: u32, + pub id: String, pub name: String, } -impl TryFrom for Instrument { - type Error = Error; - fn try_from(row: InstrumentRow) -> Result { - let instrument = Instrument { - id: row.id.try_into()?, - name: row.name, - }; - - Ok(instrument) - } -} - impl Database { /// Update an existing instrument or insert a new one. pub fn update_instrument(&self, instrument: Instrument) -> Result<()> { self.defer_foreign_keys()?; self.connection.transaction(|| { - let row: InstrumentRow = instrument.into(); diesel::replace_into(instruments::table) - .values(row) + .values(instrument) .execute(&self.connection) })?; @@ -59,24 +27,19 @@ impl Database { } /// Get an existing instrument. - pub fn get_instrument(&self, id: u32) -> Result> { - let row = instruments::table - .filter(instruments::id.eq(id as i64)) - .load::(&self.connection)? - .first() - .cloned(); - - let instrument = match row { - Some(row) => Some(row.try_into()?), - None => None, - }; + pub fn get_instrument(&self, id: &str) -> Result> { + let instrument = instruments::table + .filter(instruments::id.eq(id)) + .load::(&self.connection)? + .into_iter() + .next(); Ok(instrument) } /// Delete an existing instrument. - pub fn delete_instrument(&self, id: u32) -> Result<()> { - diesel::delete(instruments::table.filter(instruments::id.eq(id as i64))) + pub fn delete_instrument(&self, id: &str) -> Result<()> { + diesel::delete(instruments::table.filter(instruments::id.eq(id))) .execute(&self.connection)?; Ok(()) @@ -84,12 +47,7 @@ impl Database { /// Get all existing instruments. pub fn get_instruments(&self) -> Result> { - let mut instruments = Vec::::new(); - - let rows = instruments::table.load::(&self.connection)?; - for row in rows { - instruments.push(row.try_into()?); - } + let instruments = instruments::table.load::(&self.connection)?; Ok(instruments) } diff --git a/musicus/src/database/mod.rs b/musicus/src/database/mod.rs index 409435f..a8e94ed 100644 --- a/musicus/src/database/mod.rs +++ b/musicus/src/database/mod.rs @@ -27,6 +27,14 @@ mod schema; // This makes the SQL migration scripts accessible from the code. embed_migrations!(); +/// Generate a random string suitable as an item ID. +pub fn generate_id() -> String { + let mut buffer = uuid::Uuid::encode_buffer(); + let id = uuid::Uuid::new_v4().to_simple().encode_lower(&mut buffer); + + id.to_string() +} + /// Interface to a Musicus database. pub struct Database { connection: SqliteConnection, diff --git a/musicus/src/database/persons.rs b/musicus/src/database/persons.rs index 7c67c8f..ab84271 100644 --- a/musicus/src/database/persons.rs +++ b/musicus/src/database/persons.rs @@ -1,52 +1,18 @@ use super::schema::persons; use super::Database; -use anyhow::{Error, Result}; +use anyhow::Result; use diesel::prelude::*; -use diesel::{Insertable, Queryable}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; - -/// Database table data for a person. -#[derive(Insertable, Queryable, Debug, Clone)] -#[table_name = "persons"] -struct PersonRow { - pub id: i64, - pub first_name: String, - pub last_name: String, -} - -impl From for PersonRow { - fn from(person: Person) -> Self { - PersonRow { - id: person.id as i64, - first_name: person.first_name, - last_name: person.last_name, - } - } -} /// A person that is a composer, an interpret or both. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Insertable, Queryable, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Person { - pub id: u32, + pub id: String, pub first_name: String, pub last_name: String, } -impl TryFrom for Person { - type Error = Error; - fn try_from(row: PersonRow) -> Result { - let person = Person { - id: row.id.try_into()?, - first_name: row.first_name, - last_name: row.last_name, - }; - - Ok(person) - } -} - impl Person { /// Get the full name in the form "First Last". pub fn name_fl(&self) -> String { @@ -65,9 +31,8 @@ impl Database { self.defer_foreign_keys()?; self.connection.transaction(|| { - let row: PersonRow = person.into(); diesel::replace_into(persons::table) - .values(row) + .values(person) .execute(&self.connection) })?; @@ -75,36 +40,26 @@ impl Database { } /// Get an existing person. - pub fn get_person(&self, id: u32) -> Result> { - let row = persons::table - .filter(persons::id.eq(id as i64)) - .load::(&self.connection)? - .first() - .cloned(); - - let person = match row { - Some(row) => Some(row.try_into()?), - None => None, - }; + pub fn get_person(&self, id: &str) -> Result> { + let person = persons::table + .filter(persons::id.eq(id)) + .load::(&self.connection)? + .into_iter() + .next(); Ok(person) } /// Delete an existing person. - pub fn delete_person(&self, id: u32) -> Result<()> { - diesel::delete(persons::table.filter(persons::id.eq(id as i64))) - .execute(&self.connection)?; + pub fn delete_person(&self, id: &str) -> Result<()> { + diesel::delete(persons::table.filter(persons::id.eq(id))).execute(&self.connection)?; + Ok(()) } /// Get all existing persons. pub fn get_persons(&self) -> Result> { - let mut persons = Vec::::new(); - - let rows = persons::table.load::(&self.connection)?; - for row in rows { - persons.push(row.try_into()?); - } + let persons = persons::table.load::(&self.connection)?; Ok(persons) } diff --git a/musicus/src/database/recordings.rs b/musicus/src/database/recordings.rs index 9284679..886f067 100644 --- a/musicus/src/database/recordings.rs +++ b/musicus/src/database/recordings.rs @@ -10,16 +10,16 @@ use std::convert::TryInto; #[derive(Insertable, Queryable, Debug, Clone)] #[table_name = "recordings"] struct RecordingRow { - pub id: i64, - pub work: i64, + pub id: String, + pub work: String, pub comment: String, } impl From for RecordingRow { fn from(recording: Recording) -> Self { RecordingRow { - id: recording.id as i64, - work: recording.work.id as i64, + id: recording.id, + work: recording.work.id, comment: recording.comment, } } @@ -30,10 +30,10 @@ impl From for RecordingRow { #[table_name = "performances"] struct PerformanceRow { pub id: i64, - pub recording: i64, - pub person: Option, - pub ensemble: Option, - pub role: Option, + pub recording: String, + pub person: Option, + pub ensemble: Option, + pub role: Option, } /// How a person or ensemble was involved in a recording. @@ -88,7 +88,7 @@ impl Performance { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Recording { - pub id: u32, + pub id: String, pub work: Work, pub comment: String, pub performances: Vec, @@ -114,9 +114,9 @@ impl Database { pub fn update_recording(&self, recording: Recording) -> Result<()> { self.defer_foreign_keys()?; self.connection.transaction::<(), Error, _>(|| { - self.delete_recording(recording.id)?; + let recording_id = &recording.id; + self.delete_recording(recording_id)?; - let recording_id = recording.id as i64; let row: RecordingRow = recording.clone().into(); diesel::insert_into(recordings::table) .values(row) @@ -125,10 +125,10 @@ impl Database { for performance in recording.performances { let row = PerformanceRow { id: rand::random(), - recording: recording_id, - person: performance.person.map(|person| person.id as i64), - ensemble: performance.ensemble.map(|ensemble| ensemble.id as i64), - role: performance.role.map(|role| role.id as i64), + recording: recording_id.to_string(), + person: performance.person.map(|person| person.id), + ensemble: performance.ensemble.map(|ensemble| ensemble.id), + role: performance.role.map(|role| role.id), }; diesel::insert_into(performances::table) @@ -147,28 +147,28 @@ impl Database { let mut performance_descriptions: Vec = Vec::new(); let performance_rows = performances::table - .filter(performances::recording.eq(row.id)) + .filter(performances::recording.eq(&row.id)) .load::(&self.connection)?; for row in performance_rows { performance_descriptions.push(Performance { person: match row.person { Some(id) => Some( - self.get_person(id.try_into()?)? + self.get_person(&id)? .ok_or(anyhow!("No person with ID: {}", id))?, ), None => None, }, ensemble: match row.ensemble { Some(id) => Some( - self.get_ensemble(id.try_into()?)? + self.get_ensemble(&id)? .ok_or(anyhow!("No ensemble with ID: {}", id))?, ), None => None, }, role: match row.role { Some(id) => Some( - self.get_instrument(id.try_into()?)? + self.get_instrument(&id)? .ok_or(anyhow!("No instrument with ID: {}", id))?, ), None => None, @@ -176,13 +176,13 @@ impl Database { }); } - let work_id: u32 = row.work.try_into()?; + let work_id = &row.work; let work = self .get_work(work_id)? .ok_or(anyhow!("Work doesn't exist: {}", work_id))?; let recording_description = Recording { - id: row.id.try_into()?, + id: row.id, work, comment: row.comment.clone(), performances: performance_descriptions, @@ -192,13 +192,13 @@ impl Database { } /// Get all available information on all recordings where a person is performing. - pub fn get_recordings_for_person(&self, person_id: u32) -> Result> { + pub fn get_recordings_for_person(&self, person_id: &str) -> Result> { let mut recordings: Vec = Vec::new(); let rows = recordings::table .inner_join(performances::table.on(performances::recording.eq(recordings::id))) .inner_join(persons::table.on(persons::id.nullable().eq(performances::person))) - .filter(persons::id.eq(person_id as i64)) + .filter(persons::id.eq(person_id)) .select(recordings::table::all_columns()) .load::(&self.connection)?; @@ -210,13 +210,13 @@ impl Database { } /// Get all available information on all recordings where an ensemble is performing. - pub fn get_recordings_for_ensemble(&self, ensemble_id: u32) -> Result> { + pub fn get_recordings_for_ensemble(&self, ensemble_id: &str) -> Result> { let mut recordings: Vec = Vec::new(); let rows = recordings::table .inner_join(performances::table.on(performances::recording.eq(recordings::id))) .inner_join(ensembles::table.on(ensembles::id.nullable().eq(performances::ensemble))) - .filter(ensembles::id.eq(ensemble_id as i64)) + .filter(ensembles::id.eq(ensemble_id)) .select(recordings::table::all_columns()) .load::(&self.connection)?; @@ -228,11 +228,11 @@ impl Database { } /// Get allavailable information on all recordings of a work. - pub fn get_recordings_for_work(&self, work_id: u32) -> Result> { + pub fn get_recordings_for_work(&self, work_id: &str) -> Result> { let mut recordings: Vec = Vec::new(); let rows = recordings::table - .filter(recordings::work.eq(work_id as i64)) + .filter(recordings::work.eq(work_id)) .load::(&self.connection)?; for row in rows { @@ -244,8 +244,8 @@ impl Database { /// Delete an existing recording. This will fail if there are still references to this /// recording from other tables that are not directly part of the recording data. - pub fn delete_recording(&self, id: u32) -> Result<()> { - diesel::delete(recordings::table.filter(recordings::id.eq(id as i64))) + pub fn delete_recording(&self, id: &str) -> Result<()> { + diesel::delete(recordings::table.filter(recordings::id.eq(id))) .execute(&self.connection)?; Ok(()) } diff --git a/musicus/src/database/schema.rs b/musicus/src/database/schema.rs index 8c7c441..55a0457 100644 --- a/musicus/src/database/schema.rs +++ b/musicus/src/database/schema.rs @@ -1,6 +1,6 @@ table! { ensembles (id) { - id -> BigInt, + id -> Text, name -> Text, } } @@ -8,14 +8,14 @@ table! { table! { instrumentations (id) { id -> BigInt, - work -> BigInt, - instrument -> BigInt, + work -> Text, + instrument -> Text, } } table! { instruments (id) { - id -> BigInt, + id -> Text, name -> Text, } } @@ -23,16 +23,16 @@ table! { table! { performances (id) { id -> BigInt, - recording -> BigInt, - person -> Nullable, - ensemble -> Nullable, - role -> Nullable, + recording -> Text, + person -> Nullable, + ensemble -> Nullable, + role -> Nullable, } } table! { persons (id) { - id -> BigInt, + id -> Text, first_name -> Text, last_name -> Text, } @@ -40,8 +40,8 @@ table! { table! { recordings (id) { - id -> BigInt, - work -> BigInt, + id -> Text, + work -> Text, comment -> Text, } } @@ -50,7 +50,7 @@ table! { tracks (id) { id -> BigInt, file_name -> Text, - recording -> BigInt, + recording -> Text, track_index -> Integer, work_parts -> Text, } @@ -59,17 +59,17 @@ table! { table! { work_parts (id) { id -> BigInt, - work -> BigInt, + work -> Text, part_index -> BigInt, title -> Text, - composer -> Nullable, + composer -> Nullable, } } table! { work_sections (id) { id -> BigInt, - work -> BigInt, + work -> Text, title -> Text, before_index -> BigInt, } @@ -77,8 +77,8 @@ table! { table! { works (id) { - id -> BigInt, - composer -> BigInt, + id -> Text, + composer -> Text, title -> Text, } } diff --git a/musicus/src/database/thread.rs b/musicus/src/database/thread.rs index 7681d04..5a35e36 100644 --- a/musicus/src/database/thread.rs +++ b/musicus/src/database/thread.rs @@ -8,28 +8,28 @@ use std::thread; /// An action the database thread can perform. enum Action { UpdatePerson(Person, Sender>), - GetPerson(u32, Sender>>), - DeletePerson(u32, Sender>), + GetPerson(String, Sender>>), + DeletePerson(String, Sender>), GetPersons(Sender>>), UpdateInstrument(Instrument, Sender>), - GetInstrument(u32, Sender>>), - DeleteInstrument(u32, Sender>), + GetInstrument(String, Sender>>), + DeleteInstrument(String, Sender>), GetInstruments(Sender>>), UpdateWork(Work, Sender>), - DeleteWork(u32, Sender>), - GetWorks(u32, Sender>>), + DeleteWork(String, Sender>), + GetWorks(String, Sender>>), UpdateEnsemble(Ensemble, Sender>), - GetEnsemble(u32, Sender>>), - DeleteEnsemble(u32, Sender>), + GetEnsemble(String, Sender>>), + DeleteEnsemble(String, Sender>), GetEnsembles(Sender>>), UpdateRecording(Recording, Sender>), - DeleteRecording(u32, Sender>), - GetRecordingsForPerson(u32, Sender>>), - GetRecordingsForEnsemble(u32, Sender>>), - GetRecordingsForWork(u32, Sender>>), - UpdateTracks(u32, Vec, Sender>), - DeleteTracks(u32, Sender>), - GetTracks(u32, Sender>>), + DeleteRecording(String, Sender>), + GetRecordingsForPerson(String, Sender>>), + GetRecordingsForEnsemble(String, Sender>>), + GetRecordingsForWork(String, Sender>>), + UpdateTracks(String, Vec, Sender>), + DeleteTracks(String, Sender>), + GetTracks(String, Sender>>), Stop(Sender<()>), } @@ -64,10 +64,10 @@ impl DbThread { sender.send(db.update_person(person)).unwrap(); } GetPerson(id, sender) => { - sender.send(db.get_person(id)).unwrap(); + sender.send(db.get_person(&id)).unwrap(); } DeletePerson(id, sender) => { - sender.send(db.delete_person(id)).unwrap(); + sender.send(db.delete_person(&id)).unwrap(); } GetPersons(sender) => { sender.send(db.get_persons()).unwrap(); @@ -76,10 +76,10 @@ impl DbThread { sender.send(db.update_instrument(instrument)).unwrap(); } GetInstrument(id, sender) => { - sender.send(db.get_instrument(id)).unwrap(); + sender.send(db.get_instrument(&id)).unwrap(); } DeleteInstrument(id, sender) => { - sender.send(db.delete_instrument(id)).unwrap(); + sender.send(db.delete_instrument(&id)).unwrap(); } GetInstruments(sender) => { sender.send(db.get_instruments()).unwrap(); @@ -88,19 +88,19 @@ impl DbThread { sender.send(db.update_work(work)).unwrap(); } DeleteWork(id, sender) => { - sender.send(db.delete_work(id)).unwrap(); + sender.send(db.delete_work(&id)).unwrap(); } GetWorks(id, sender) => { - sender.send(db.get_works(id)).unwrap(); + sender.send(db.get_works(&id)).unwrap(); } UpdateEnsemble(ensemble, sender) => { sender.send(db.update_ensemble(ensemble)).unwrap(); } GetEnsemble(id, sender) => { - sender.send(db.get_ensemble(id)).unwrap(); + sender.send(db.get_ensemble(&id)).unwrap(); } DeleteEnsemble(id, sender) => { - sender.send(db.delete_ensemble(id)).unwrap(); + sender.send(db.delete_ensemble(&id)).unwrap(); } GetEnsembles(sender) => { sender.send(db.get_ensembles()).unwrap(); @@ -109,25 +109,27 @@ impl DbThread { sender.send(db.update_recording(recording)).unwrap(); } DeleteRecording(id, sender) => { - sender.send(db.delete_recording(id)).unwrap(); + sender.send(db.delete_recording(&id)).unwrap(); } GetRecordingsForPerson(id, sender) => { - sender.send(db.get_recordings_for_person(id)).unwrap(); + sender.send(db.get_recordings_for_person(&id)).unwrap(); } GetRecordingsForEnsemble(id, sender) => { - sender.send(db.get_recordings_for_ensemble(id)).unwrap(); + sender.send(db.get_recordings_for_ensemble(&id)).unwrap(); } GetRecordingsForWork(id, sender) => { - sender.send(db.get_recordings_for_work(id)).unwrap(); + sender.send(db.get_recordings_for_work(&id)).unwrap(); } UpdateTracks(recording_id, tracks, sender) => { - sender.send(db.update_tracks(recording_id, tracks)).unwrap(); + sender + .send(db.update_tracks(&recording_id, tracks)) + .unwrap(); } DeleteTracks(recording_id, sender) => { - sender.send(db.delete_tracks(recording_id)).unwrap(); + sender.send(db.delete_tracks(&recording_id)).unwrap(); } GetTracks(recording_id, sender) => { - sender.send(db.get_tracks(recording_id)).unwrap(); + sender.send(db.get_tracks(&recording_id)).unwrap(); } Stop(sender) => { sender.send(()).unwrap(); @@ -149,17 +151,18 @@ impl DbThread { } /// Get an existing person. - pub async fn get_person(&self, id: u32) -> Result> { + pub async fn get_person(&self, id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(GetPerson(id, sender))?; + self.action_sender.send(GetPerson(id.to_string(), sender))?; receiver.await? } /// Delete an existing person. This will fail, if there are still other items referencing /// this person. - pub async fn delete_person(&self, id: u32) -> Result<()> { + pub async fn delete_person(&self, id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(DeletePerson(id, sender))?; + self.action_sender + .send(DeletePerson(id.to_string(), sender))?; receiver.await? } @@ -179,17 +182,19 @@ impl DbThread { } /// Get an existing instrument. - pub async fn get_instrument(&self, id: u32) -> Result> { + pub async fn get_instrument(&self, id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(GetInstrument(id, sender))?; + self.action_sender + .send(GetInstrument(id.to_string(), sender))?; receiver.await? } /// Delete an existing instrument. This will fail, if there are still other items referencing /// this instrument. - pub async fn delete_instrument(&self, id: u32) -> Result<()> { + pub async fn delete_instrument(&self, id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(DeleteInstrument(id, sender))?; + self.action_sender + .send(DeleteInstrument(id.to_string(), sender))?; receiver.await? } @@ -209,16 +214,18 @@ impl DbThread { /// Delete an existing work. This will fail, if there are still other items referencing /// this work. - pub async fn delete_work(&self, id: u32) -> Result<()> { + pub async fn delete_work(&self, id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(DeleteWork(id, sender))?; + self.action_sender + .send(DeleteWork(id.to_string(), sender))?; receiver.await? } /// Get information on all existing works by a composer. - pub async fn get_works(&self, person_id: u32) -> Result> { + pub async fn get_works(&self, person_id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(GetWorks(person_id, sender))?; + self.action_sender + .send(GetWorks(person_id.to_string(), sender))?; receiver.await? } @@ -230,17 +237,19 @@ impl DbThread { } /// Get an existing ensemble. - pub async fn get_ensemble(&self, id: u32) -> Result> { + pub async fn get_ensemble(&self, id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(GetEnsemble(id, sender))?; + self.action_sender + .send(GetEnsemble(id.to_string(), sender))?; receiver.await? } /// Delete an existing ensemble. This will fail, if there are still other items referencing /// this ensemble. - pub async fn delete_ensemble(&self, id: u32) -> Result<()> { + pub async fn delete_ensemble(&self, id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(DeleteEnsemble(id, sender))?; + self.action_sender + .send(DeleteEnsemble(id.to_string(), sender))?; receiver.await? } @@ -260,61 +269,59 @@ impl DbThread { } /// Delete an existing recording. - pub async fn delete_recording(&self, id: u32) -> Result<()> { + pub async fn delete_recording(&self, id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(DeleteRecording(id, sender))?; + self.action_sender + .send(DeleteRecording(id.to_string(), sender))?; receiver.await? } /// Get information on all recordings in which a person performs. - pub async fn get_recordings_for_person(&self, person_id: u32) -> Result> { + pub async fn get_recordings_for_person(&self, person_id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); self.action_sender - .send(GetRecordingsForPerson(person_id, sender))?; + .send(GetRecordingsForPerson(person_id.to_string(), sender))?; receiver.await? } /// Get information on all recordings in which an ensemble performs. - pub async fn get_recordings_for_ensemble(&self, ensemble_id: u32) -> Result> { + pub async fn get_recordings_for_ensemble(&self, ensemble_id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); self.action_sender - .send(GetRecordingsForEnsemble(ensemble_id, sender))?; + .send(GetRecordingsForEnsemble(ensemble_id.to_string(), sender))?; receiver.await? } /// Get information on all recordings of a work. - pub async fn get_recordings_for_work(&self, work_id: u32) -> Result> { + pub async fn get_recordings_for_work(&self, work_id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); self.action_sender - .send(GetRecordingsForWork(work_id, sender))?; + .send(GetRecordingsForWork(work_id.to_string(), sender))?; receiver.await? } /// Add or change the tracks associated with a recording. This will fail, if there are still /// other items referencing this recording. - pub async fn update_tracks( - &self, - recording_id: u32, - tracks: Vec, - ) -> Result<()> { + pub async fn update_tracks(&self, recording_id: &str, tracks: Vec) -> Result<()> { let (sender, receiver) = oneshot::channel(); self.action_sender - .send(UpdateTracks(recording_id, tracks, sender))?; + .send(UpdateTracks(recording_id.to_string(), tracks, sender))?; receiver.await? } /// Delete all tracks associated with a recording. - pub async fn delete_tracks(&self, recording_id: u32) -> Result<()> { + pub async fn delete_tracks(&self, recording_id: &str) -> Result<()> { let (sender, receiver) = oneshot::channel(); self.action_sender - .send(DeleteTracks(recording_id, sender))?; + .send(DeleteTracks(recording_id.to_string(), sender))?; receiver.await? } /// Get all tracks associated with a recording. - pub async fn get_tracks(&self, recording_id: u32) -> Result> { + pub async fn get_tracks(&self, recording_id: &str) -> Result> { let (sender, receiver) = oneshot::channel(); - self.action_sender.send(GetTracks(recording_id, sender))?; + self.action_sender + .send(GetTracks(recording_id.to_string(), sender))?; receiver.await? } diff --git a/musicus/src/database/tracks.rs b/musicus/src/database/tracks.rs index 1c758ab..f0f8375 100644 --- a/musicus/src/database/tracks.rs +++ b/musicus/src/database/tracks.rs @@ -10,7 +10,7 @@ use std::convert::{TryFrom, TryInto}; struct TrackRow { pub id: i64, pub file_name: String, - pub recording: i64, + pub recording: String, pub track_index: i32, pub work_parts: String, } @@ -43,14 +43,14 @@ impl TryFrom for Track { impl Database { /// Insert or update tracks for the specified recording. - pub fn update_tracks(&self, recording_id: u32, tracks: Vec) -> Result<()> { + pub fn update_tracks(&self, recording_id: &str, tracks: Vec) -> Result<()> { self.delete_tracks(recording_id)?; for (index, track) in tracks.iter().enumerate() { let row = TrackRow { id: rand::random(), file_name: track.file_name.clone(), - recording: recording_id as i64, + recording: recording_id.to_string(), track_index: index.try_into()?, work_parts: track .work_parts @@ -69,19 +69,19 @@ impl Database { } /// Delete all tracks for the specified recording. - pub fn delete_tracks(&self, recording_id: u32) -> Result<()> { - diesel::delete(tracks::table.filter(tracks::recording.eq(recording_id as i64))) + pub fn delete_tracks(&self, recording_id: &str) -> Result<()> { + diesel::delete(tracks::table.filter(tracks::recording.eq(recording_id))) .execute(&self.connection)?; Ok(()) } /// Get all tracks of the specified recording. - pub fn get_tracks(&self, recording_id: u32) -> Result> { + pub fn get_tracks(&self, recording_id: &str) -> Result> { let mut tracks = Vec::::new(); let rows = tracks::table - .filter(tracks::recording.eq(recording_id as i64)) + .filter(tracks::recording.eq(recording_id)) .order_by(tracks::track_index) .load::(&self.connection)?; diff --git a/musicus/src/database/works.rs b/musicus/src/database/works.rs index cbc92d4..b7b0919 100644 --- a/musicus/src/database/works.rs +++ b/musicus/src/database/works.rs @@ -10,16 +10,16 @@ use std::convert::TryInto; #[derive(Insertable, Queryable, Debug, Clone)] #[table_name = "works"] struct WorkRow { - pub id: i64, - pub composer: i64, + pub id: String, + pub composer: String, pub title: String, } impl From for WorkRow { fn from(work: Work) -> Self { WorkRow { - id: work.id as i64, - composer: work.composer.id as i64, + id: work.id, + composer: work.composer.id, title: work.title, } } @@ -30,8 +30,8 @@ impl From for WorkRow { #[table_name = "instrumentations"] struct InstrumentationRow { pub id: i64, - pub work: i64, - pub instrument: i64, + pub work: String, + pub instrument: String, } /// Table row data for a work part. @@ -39,10 +39,10 @@ struct InstrumentationRow { #[table_name = "work_parts"] struct WorkPartRow { pub id: i64, - pub work: i64, + pub work: String, pub part_index: i64, pub title: String, - pub composer: Option, + pub composer: Option, } /// Table row data for a work section. @@ -50,7 +50,7 @@ struct WorkPartRow { #[table_name = "work_sections"] struct WorkSectionRow { pub id: i64, - pub work: i64, + pub work: String, pub title: String, pub before_index: i64, } @@ -74,7 +74,7 @@ pub struct WorkSection { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Work { - pub id: u32, + pub id: String, pub title: String, pub composer: Person, pub instruments: Vec, @@ -97,9 +97,9 @@ impl Database { self.defer_foreign_keys()?; self.connection.transaction::<(), Error, _>(|| { - self.delete_work(work.id)?; + let work_id = &work.id; + self.delete_work(work_id)?; - let work_id = work.id as i64; let row: WorkRow = work.clone().into(); diesel::insert_into(works::table) .values(row) @@ -115,8 +115,8 @@ impl Database { for instrument in instruments { let row = InstrumentationRow { id: rand::random(), - work: work_id, - instrument: instrument.id as i64, + work: work_id.to_string(), + instrument: instrument.id, }; diesel::insert_into(instrumentations::table) @@ -127,10 +127,10 @@ impl Database { for (index, part) in parts.into_iter().enumerate() { let row = WorkPartRow { id: rand::random(), - work: work_id, + work: work_id.to_string(), part_index: index.try_into()?, title: part.title, - composer: part.composer.map(|person| person.id as i64), + composer: part.composer.map(|person| person.id), }; diesel::insert_into(work_parts::table) @@ -141,7 +141,7 @@ impl Database { for section in sections { let row = WorkSectionRow { id: rand::random(), - work: work_id, + work: work_id.to_string(), title: section.title, before_index: section.before_index.try_into()?, }; @@ -160,9 +160,9 @@ impl Database { } /// Get an existing work. - pub fn get_work(&self, id: u32) -> Result> { + pub fn get_work(&self, id: &str) -> Result> { let row = works::table - .filter(works::id.eq(id as i64)) + .filter(works::id.eq(id)) .load::(&self.connection)? .first() .cloned(); @@ -180,11 +180,11 @@ impl Database { let mut instruments: Vec = Vec::new(); let instrumentations = instrumentations::table - .filter(instrumentations::work.eq(row.id)) + .filter(instrumentations::work.eq(&row.id)) .load::(&self.connection)?; for instrumentation in instrumentations { - let id: u32 = instrumentation.instrument.try_into()?; + let id = &instrumentation.instrument; instruments.push( self.get_instrument(id)? .ok_or(anyhow!("No instrument with ID: {}", id))?, @@ -194,7 +194,7 @@ impl Database { let mut parts: Vec = Vec::new(); let part_rows = work_parts::table - .filter(work_parts::work.eq(row.id)) + .filter(work_parts::work.eq(&row.id)) .load::(&self.connection)?; for part_row in part_rows { @@ -202,7 +202,7 @@ impl Database { title: part_row.title, composer: match part_row.composer { Some(composer) => Some( - self.get_person(composer.try_into()?)? + self.get_person(&composer)? .ok_or(anyhow!("No person with ID: {}", composer))?, ), None => None, @@ -213,7 +213,7 @@ impl Database { let mut sections: Vec = Vec::new(); let section_rows = work_sections::table - .filter(work_sections::work.eq(row.id)) + .filter(work_sections::work.eq(&row.id)) .load::(&self.connection)?; for section_row in section_rows { @@ -223,13 +223,13 @@ impl Database { }); } - let person_id = row.composer.try_into()?; + let person_id = &row.composer; let person = self .get_person(person_id)? .ok_or(anyhow!("Person doesn't exist: {}", person_id))?; Ok(Work { - id: row.id.try_into()?, + id: row.id, composer: person, title: row.title, instruments, @@ -240,17 +240,17 @@ impl Database { /// Delete an existing work. This will fail if there are still other tables that relate to /// this work except for the things that are part of the information on the work it - pub fn delete_work(&self, id: u32) -> Result<()> { - diesel::delete(works::table.filter(works::id.eq(id as i64))).execute(&self.connection)?; + pub fn delete_work(&self, id: &str) -> Result<()> { + diesel::delete(works::table.filter(works::id.eq(id))).execute(&self.connection)?; Ok(()) } /// Get all existing works by a composer and related information from other tables. - pub fn get_works(&self, composer_id: u32) -> Result> { + pub fn get_works(&self, composer_id: &str) -> Result> { let mut works: Vec = Vec::new(); let rows = works::table - .filter(works::composer.eq(composer_id as i64)) + .filter(works::composer.eq(composer_id)) .load::(&self.connection)?; for row in rows { diff --git a/musicus/src/dialogs/ensemble_editor.rs b/musicus/src/dialogs/ensemble_editor.rs index 8b5e521..64d2840 100644 --- a/musicus/src/dialogs/ensemble_editor.rs +++ b/musicus/src/dialogs/ensemble_editor.rs @@ -12,7 +12,7 @@ where backend: Rc, window: libhandy::Window, callback: F, - id: u32, + id: String, name_entry: gtk::Entry, } @@ -38,7 +38,7 @@ where name_entry.set_text(&ensemble.name); ensemble.id } - None => rand::random::().into(), + None => generate_id(), }; let result = Rc::new(EnsembleEditor { @@ -55,7 +55,7 @@ where save_button.connect_clicked(clone!(@strong result => move |_| { let ensemble = Ensemble { - id: result.id, + id: result.id.clone(), name: result.name_entry.get_text().to_string(), }; diff --git a/musicus/src/dialogs/instrument_editor.rs b/musicus/src/dialogs/instrument_editor.rs index 1b397a6..ed3fe8e 100644 --- a/musicus/src/dialogs/instrument_editor.rs +++ b/musicus/src/dialogs/instrument_editor.rs @@ -12,7 +12,7 @@ where backend: Rc, window: libhandy::Window, callback: F, - id: u32, + id: String, name_entry: gtk::Entry, } @@ -26,8 +26,7 @@ where instrument: Option, callback: F, ) -> Rc { - let builder = - gtk::Builder::from_resource("/de/johrpan/musicus/ui/instrument_editor.ui"); + let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/instrument_editor.ui"); get_widget!(builder, libhandy::Window, window); get_widget!(builder, gtk::Button, cancel_button); @@ -39,7 +38,7 @@ where name_entry.set_text(&instrument.name); instrument.id } - None => rand::random::().into(), + None => generate_id(), }; let result = Rc::new(InstrumentEditor { @@ -56,7 +55,7 @@ where save_button.connect_clicked(clone!(@strong result => move |_| { let instrument = Instrument { - id: result.id, + id: result.id.clone(), name: result.name_entry.get_text().to_string(), }; diff --git a/musicus/src/dialogs/person_editor.rs b/musicus/src/dialogs/person_editor.rs index 0457a78..8f1545b 100644 --- a/musicus/src/dialogs/person_editor.rs +++ b/musicus/src/dialogs/person_editor.rs @@ -10,6 +10,7 @@ where F: Fn(Person) -> () + 'static, { backend: Rc, + id: String, window: libhandy::Window, callback: F, id: u32, diff --git a/musicus/src/dialogs/recording/recording_editor.rs b/musicus/src/dialogs/recording/recording_editor.rs index 2847c30..44afbce 100644 --- a/musicus/src/dialogs/recording/recording_editor.rs +++ b/musicus/src/dialogs/recording/recording_editor.rs @@ -20,7 +20,7 @@ pub struct RecordingEditor { work_label: gtk::Label, comment_entry: gtk::Entry, performance_list: Rc>, - id: u32, + id: String, work: RefCell>, performances: RefCell>, selected_cb: RefCell ()>>>, @@ -59,7 +59,7 @@ impl RecordingEditor { comment_entry.set_text(&recording.comment); (recording.id, Some(recording.work), recording.performances) } - None => (rand::random::().into(), None, Vec::new()), + None => (generate_id(), None, Vec::new()), }; let this = Rc::new(RecordingEditor { @@ -88,7 +88,7 @@ impl RecordingEditor { this.save_button .connect_clicked(clone!(@strong this => move |_| { let recording = Recording { - id: this.id, + id: this.id.clone(), work: this.work.borrow().clone().expect("Tried to create recording without work!"), comment: this.comment_entry.get_text().to_string(), performances: this.performances.borrow().clone(), diff --git a/musicus/src/dialogs/recording/recording_selector_person_screen.rs b/musicus/src/dialogs/recording/recording_selector_person_screen.rs index c0279a1..648b57c 100644 --- a/musicus/src/dialogs/recording/recording_selector_person_screen.rs +++ b/musicus/src/dialogs/recording/recording_selector_person_screen.rs @@ -92,7 +92,7 @@ impl RecordingSelectorPersonScreen { let context = glib::MainContext::default(); let clone = this.clone(); context.spawn_local(async move { - let works = clone.backend.db().get_works(person.id).await.unwrap(); + let works = clone.backend.db().get_works(&person.id).await.unwrap(); clone.work_list.show_items(works); clone.stack.set_visible_child_name("content"); diff --git a/musicus/src/dialogs/recording/recording_selector_work_screen.rs b/musicus/src/dialogs/recording/recording_selector_work_screen.rs index b91c30b..31ee47b 100644 --- a/musicus/src/dialogs/recording/recording_selector_work_screen.rs +++ b/musicus/src/dialogs/recording/recording_selector_work_screen.rs @@ -90,7 +90,7 @@ impl RecordingSelectorWorkScreen { let recordings = clone .backend .db() - .get_recordings_for_work(work.id) + .get_recordings_for_work(&work.id) .await .unwrap(); diff --git a/musicus/src/dialogs/tracks_editor.rs b/musicus/src/dialogs/tracks_editor.rs index ecab187..d88a590 100644 --- a/musicus/src/dialogs/tracks_editor.rs +++ b/musicus/src/dialogs/tracks_editor.rs @@ -81,7 +81,7 @@ impl TracksEditor { let this = this.clone(); context.spawn_local(async move { this.backend.db().update_tracks( - this.recording.borrow().as_ref().unwrap().id as u32, + &this.recording.borrow().as_ref().unwrap().id, this.tracks.borrow().clone(), ).await.unwrap(); diff --git a/musicus/src/dialogs/work/work_editor.rs b/musicus/src/dialogs/work/work_editor.rs index f2e8d1f..5693c7e 100644 --- a/musicus/src/dialogs/work/work_editor.rs +++ b/musicus/src/dialogs/work/work_editor.rs @@ -29,7 +29,7 @@ pub struct WorkEditor { composer_label: gtk::Label, instrument_list: Rc>, part_list: Rc>, - id: u32, + id: String, composer: RefCell>, instruments: RefCell>, structure: RefCell>, @@ -91,7 +91,7 @@ impl WorkEditor { (work.id, Some(work.composer), work.instruments, structure) } - None => (rand::random::().into(), None, Vec::new(), Vec::new()), + None => (generate_id(), None, Vec::new(), Vec::new()), }; let this = Rc::new(Self { @@ -137,7 +137,7 @@ impl WorkEditor { } let work = Work { - id: this.id, + id: this.id.clone(), title: this.title_entry.get_text().to_string(), composer: this.composer.borrow().clone().expect("Tried to create work without composer!"), instruments: this.instruments.borrow().clone(), diff --git a/musicus/src/dialogs/work/work_selector_person_screen.rs b/musicus/src/dialogs/work/work_selector_person_screen.rs index 95fd233..ff9ce16 100644 --- a/musicus/src/dialogs/work/work_selector_person_screen.rs +++ b/musicus/src/dialogs/work/work_selector_person_screen.rs @@ -80,7 +80,7 @@ impl WorkSelectorPersonScreen { let context = glib::MainContext::default(); let clone = this.clone(); context.spawn_local(async move { - let works = clone.backend.db().get_works(person.id).await.unwrap(); + let works = clone.backend.db().get_works(&person.id).await.unwrap(); clone.work_list.show_items(works); clone.stack.set_visible_child_name("content"); diff --git a/musicus/src/screens/ensemble_screen.rs b/musicus/src/screens/ensemble_screen.rs index e9740b0..02cec8d 100644 --- a/musicus/src/screens/ensemble_screen.rs +++ b/musicus/src/screens/ensemble_screen.rs @@ -116,7 +116,7 @@ impl EnsembleScreen { let context = glib::MainContext::default(); let clone = result.clone(); context.spawn_local(async move { - clone.backend.db().delete_ensemble(clone.ensemble.id).await.unwrap(); + clone.backend.db().delete_ensemble(&clone.ensemble.id).await.unwrap(); }); })); @@ -126,7 +126,7 @@ impl EnsembleScreen { let recordings = clone .backend .db() - .get_recordings_for_ensemble(clone.ensemble.id) + .get_recordings_for_ensemble(&clone.ensemble.id) .await .unwrap(); diff --git a/musicus/src/screens/person_screen.rs b/musicus/src/screens/person_screen.rs index 8caf247..802c682 100644 --- a/musicus/src/screens/person_screen.rs +++ b/musicus/src/screens/person_screen.rs @@ -145,14 +145,14 @@ impl PersonScreen { })); edit_action.connect_activate(clone!(@strong result => move |_, _| { - PersonEditor::new(result.backend.clone(), &result.window, Some(result.person.clone()), |_| {}).show(); + PersonEditor::new(result.backend.clone(), &result.window, Some(result.person.clone())).show(); })); delete_action.connect_activate(clone!(@strong result => move |_, _| { let context = glib::MainContext::default(); let clone = result.clone(); context.spawn_local(async move { - clone.backend.db().delete_person(clone.person.id).await.unwrap(); + clone.backend.db().delete_person(&clone.person.id).await.unwrap(); }); })); @@ -162,13 +162,13 @@ impl PersonScreen { let works = clone .backend .db() - .get_works(clone.person.id as u32) + .get_works(&clone.person.id) .await .unwrap(); let recordings = clone .backend .db() - .get_recordings_for_person(clone.person.id as u32) + .get_recordings_for_person(&clone.person.id) .await .unwrap(); diff --git a/musicus/src/screens/recording_screen.rs b/musicus/src/screens/recording_screen.rs index ada6ab5..bded41c 100644 --- a/musicus/src/screens/recording_screen.rs +++ b/musicus/src/screens/recording_screen.rs @@ -118,7 +118,7 @@ impl RecordingScreen { let context = glib::MainContext::default(); let clone = result.clone(); context.spawn_local(async move { - clone.backend.db().delete_recording(clone.recording.id).await.unwrap(); + clone.backend.db().delete_recording(&clone.recording.id).await.unwrap(); }); })); @@ -130,7 +130,7 @@ impl RecordingScreen { let context = glib::MainContext::default(); let clone = result.clone(); context.spawn_local(async move { - clone.backend.db().delete_tracks(clone.recording.id).await.unwrap(); + clone.backend.db().delete_tracks(&clone.recording.id).await.unwrap(); }); })); @@ -140,7 +140,7 @@ impl RecordingScreen { let tracks = clone .backend .db() - .get_tracks(clone.recording.id) + .get_tracks(&clone.recording.id) .await .unwrap(); diff --git a/musicus/src/screens/work_screen.rs b/musicus/src/screens/work_screen.rs index 496b814..76d9db4 100644 --- a/musicus/src/screens/work_screen.rs +++ b/musicus/src/screens/work_screen.rs @@ -115,7 +115,7 @@ impl WorkScreen { let context = glib::MainContext::default(); let clone = result.clone(); context.spawn_local(async move { - clone.backend.db().delete_work(clone.work.id).await.unwrap(); + clone.backend.db().delete_work(&clone.work.id).await.unwrap(); }); })); @@ -125,7 +125,7 @@ impl WorkScreen { let recordings = clone .backend .db() - .get_recordings_for_work(clone.work.id as u32) + .get_recordings_for_work(&clone.work.id) .await .unwrap();