diff --git a/lib/database.dart b/lib/database.dart index d9ac728..084104d 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -35,14 +35,6 @@ class Database extends _$Database { await customStatement('PRAGMA foreign_keys = ON'); }); - // TODO: Remove this once https://github.com/simolus3/moor/issues/453 is fixed. - Selectable 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 updatePerson(Person person) async { await into(persons).insert(person, orReplace: true); } @@ -85,7 +77,9 @@ class Database extends _$Database { Future updateRecording( Recording recording, List perfs) 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); for (final perf in perfs) { await into(performances).insert(perf); diff --git a/lib/database.moor b/lib/database.moor index 1763455..2a6e327 100644 --- a/lib/database.moor +++ b/lib/database.moor @@ -63,10 +63,10 @@ SELECT * FROM works WHERE id = :id LIMIT 1; workParts: SELECT * FROM works WHERE part_of = :id ORDER BY part_index; --- TODO: Uncomment this once https://github.com/simolus3/moor/issues/453 is fixed. --- worksByComposer(:id AS INTEGER): --- SELECT DISTINCT A.* FROM works A, works B ON A.id = B.part_of --- WHERE A.composer = :id OR B.composer = :id; +-- TODO: Maybe optimize. +worksByComposer: +SELECT DISTINCT A.* FROM works A LEFT JOIN works B ON A.id = B.part_of + WHERE A.part_of IS NULL AND A.composer = :id OR B.composer = :id; composersByWork: SELECT DISTINCT persons.* FROM persons