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:
Elias Projahn 2020-03-22 16:31:38 +01:00
parent 2ee36aacf4
commit 7f783bd016
2 changed files with 7 additions and 13 deletions

View file

@ -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