Add queries for ensembles and works

This commit is contained in:
Elias Projahn 2023-10-08 14:50:27 +02:00
parent f4a91acffa
commit 84612673c1
2 changed files with 68 additions and 2 deletions

View file

@ -136,7 +136,73 @@ impl MusicusLibrary {
recordings,
}
}
_ => LibraryResults::default(),
LibraryQuery {
person: None,
ensemble: Some(ensemble),
work: None,
..
} => {
let persons = self.con()
.prepare("SELECT DISTINCT persons.id, persons.first_name, persons.last_name FROM persons INNER JOIN works ON works.composer = persons.id INNER JOIN recordings ON recordings.work = works.id INNER JOIN performances ON performances.recording = recordings.id WHERE performances.ensemble IS ?1 AND (persons.first_name LIKE ?2 OR persons.last_name LIKE ?2) LIMIT 9")
.unwrap()
.query_map([&ensemble.id, &search], Person::from_row)
.unwrap()
.collect::<rusqlite::Result<Vec<Person>>>()
.unwrap();
let recordings = self
.con()
.prepare("SELECT DISTINCT recordings.id, works.id, works.title, persons.id, persons.first_name, persons.last_name FROM recordings INNER JOIN works ON recordings.work = works.id INNER JOIN persons ON works.composer = persons.id INNER JOIN performances ON recordings.id = performances.recording WHERE performances.ensemble IS ?1 AND (works.title LIKE ?2 OR persons.first_name LIKE ?2 OR persons.last_name LIKE ?2) LIMIT 9")
.unwrap()
.query_map([&ensemble.id, &search], Recording::from_row)
.unwrap()
.collect::<rusqlite::Result<Vec<Recording>>>()
.unwrap();
LibraryResults {
persons,
recordings,
..Default::default()
}
},
LibraryQuery {
person: Some(person),
ensemble: Some(ensemble),
work: None,
..
} => {
let recordings = self
.con()
.prepare("SELECT DISTINCT recordings.id, works.id, works.title, persons.id, persons.first_name, persons.last_name FROM recordings INNER JOIN works ON recordings.work = works.id INNER JOIN persons ON works.composer = persons.id INNER JOIN performances ON recordings.id = performances.recording WHERE works.composer IS ?1 AND performances.ensemble IS ?2 AND (works.title LIKE ?3 OR persons.first_name LIKE ?3 OR persons.last_name LIKE ?3) LIMIT 9")
.unwrap()
.query_map([&person.id, &ensemble.id, &search], Recording::from_row)
.unwrap()
.collect::<rusqlite::Result<Vec<Recording>>>()
.unwrap();
LibraryResults {
recordings,
..Default::default()
}
},
LibraryQuery {
work: Some(work),
..
} => {
let recordings = self
.con()
.prepare("SELECT DISTINCT recordings.id, works.id, works.title, persons.id, persons.first_name, persons.last_name FROM recordings INNER JOIN works ON recordings.work = works.id INNER JOIN persons ON works.composer IS persons.id WHERE works.id IS ?1")
.unwrap()
.query_map([&work.id], Recording::from_row)
.unwrap()
.collect::<rusqlite::Result<Vec<Recording>>>()
.unwrap();
LibraryResults {
recordings,
..Default::default()
}
}
}
}

View file

@ -56,7 +56,7 @@ impl MusicusSearchTag {
obj.imp().label.set_label(&match &tag {
Tag::Person(person) => person.name_fl(),
Tag::Ensemble(ensemble) => ensemble.name.clone(),
Tag::Work(work) => format!("{}: {}", &work.composer.name_fl(), &work.title),
Tag::Work(work) => work.title.clone(),
});
obj.imp().tag.set(tag).unwrap();