mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Database: Fix worksByComposer
While the previous code was indeed valid SQL is wasn't the best way to do this. Also, only works with parts where included in the result set. This is fixed now. Some optimization may still be neccessary.
This commit is contained in:
parent
2ee36aacf4
commit
7f783bd016
2 changed files with 7 additions and 13 deletions
|
|
@ -35,14 +35,6 @@ class Database extends _$Database {
|
||||||
await customStatement('PRAGMA foreign_keys = ON');
|
await customStatement('PRAGMA foreign_keys = ON');
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Remove this once https://github.com/simolus3/moor/issues/453 is fixed.
|
|
||||||
Selectable<Work> worksByComposer(int id) {
|
|
||||||
return customSelectQuery(
|
|
||||||
'SELECT DISTINCT A.* FROM works A, works B ON A.id = B.part_of WHERE A.composer = :id OR B.composer = :id',
|
|
||||||
variables: [Variable.withInt(id)],
|
|
||||||
readsFrom: {works}).map(_rowToWork);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> updatePerson(Person person) async {
|
Future<void> updatePerson(Person person) async {
|
||||||
await into(persons).insert(person, orReplace: true);
|
await into(persons).insert(person, orReplace: true);
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +77,9 @@ class Database extends _$Database {
|
||||||
Future<void> updateRecording(
|
Future<void> updateRecording(
|
||||||
Recording recording, List<Performance> perfs) async {
|
Recording recording, List<Performance> perfs) async {
|
||||||
await transaction(() async {
|
await transaction(() async {
|
||||||
await (delete(performances)..where((p) => p.recording.equals(recording.id))).go();
|
await (delete(performances)
|
||||||
|
..where((p) => p.recording.equals(recording.id)))
|
||||||
|
.go();
|
||||||
await into(recordings).insert(recording, orReplace: true);
|
await into(recordings).insert(recording, orReplace: true);
|
||||||
for (final perf in perfs) {
|
for (final perf in perfs) {
|
||||||
await into(performances).insert(perf);
|
await into(performances).insert(perf);
|
||||||
|
|
|
||||||
|
|
@ -63,10 +63,10 @@ SELECT * FROM works WHERE id = :id LIMIT 1;
|
||||||
workParts:
|
workParts:
|
||||||
SELECT * FROM works WHERE part_of = :id ORDER BY part_index;
|
SELECT * FROM works WHERE part_of = :id ORDER BY part_index;
|
||||||
|
|
||||||
-- TODO: Uncomment this once https://github.com/simolus3/moor/issues/453 is fixed.
|
-- TODO: Maybe optimize.
|
||||||
-- worksByComposer(:id AS INTEGER):
|
worksByComposer:
|
||||||
-- SELECT DISTINCT A.* FROM works A, works B ON A.id = B.part_of
|
SELECT DISTINCT A.* FROM works A LEFT JOIN works B ON A.id = B.part_of
|
||||||
-- WHERE A.composer = :id OR B.composer = :id;
|
WHERE A.part_of IS NULL AND A.composer = :id OR B.composer = :id;
|
||||||
|
|
||||||
composersByWork:
|
composersByWork:
|
||||||
SELECT DISTINCT persons.* FROM persons
|
SELECT DISTINCT persons.* FROM persons
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue