mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
The tables ensembles, roles, recordings and performances as well as corresponding queries and update logic have been added to the database.
95 lines
No EOL
2.3 KiB
Text
95 lines
No EOL
2.3 KiB
Text
CREATE TABLE persons (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
first_name TEXT NOT NULL,
|
|
last_name TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE instruments (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
name TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE works (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
composer INTEGER REFERENCES persons(id),
|
|
title TEXT NOT NULL,
|
|
part_of INTEGER REFERENCES works(id) ON DELETE CASCADE,
|
|
part_index INTEGER,
|
|
part_level INTEGER
|
|
);
|
|
|
|
CREATE TABLE instrumentations (
|
|
work INTEGER NOT NULL REFERENCES works(id) ON DELETE CASCADE,
|
|
instrument INTEGER NOT NULL REFERENCES instruments(id) ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE TABLE ensembles (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
name TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE roles (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
name TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE recordings (
|
|
id INTEGER NOT NULL PRIMARY KEY,
|
|
work INTEGER REFERENCES works(id)
|
|
);
|
|
|
|
CREATE TABLE performances (
|
|
recording INTEGER NOT NULL REFERENCES recordings(id) ON DELETE CASCADE,
|
|
person INTEGER REFERENCES persons(id) ON DELETE CASCADE,
|
|
ensemble INTEGER REFERENCES ensembles(id) ON DELETE CASCADE,
|
|
role INTEGER REFERENCES roles(id)
|
|
);
|
|
|
|
allPersons:
|
|
SELECT * FROM persons ORDER BY last_name;
|
|
|
|
personById:
|
|
SELECT * FROM persons WHERE id = :id LIMIT 1;
|
|
|
|
allInstruments:
|
|
SELECT * FROM instruments ORDER BY name;
|
|
|
|
instrumentById:
|
|
SELECT * FROM instruments WHERE id = :id LIMIT 1;
|
|
|
|
workById:
|
|
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;
|
|
|
|
instrumentsByWork:
|
|
SELECT instruments.* FROM instrumentations
|
|
JOIN instruments ON instrumentations.instrument=instruments.id
|
|
WHERE instrumentations.work = :workId;
|
|
|
|
allEnsembles:
|
|
SELECT * FROM ensembles ORDER BY name;
|
|
|
|
ensembleById:
|
|
SELECT * FROM ensembles WHERE id = :id LIMIT 1;
|
|
|
|
allRoles:
|
|
SELECT * FROM roles ORDER BY name;
|
|
|
|
roleById:
|
|
SELECT * FROM roles WHERE id = :id LIMIT 1;
|
|
|
|
recordingById:
|
|
SELECT * FROM recordings WHERE id = :id;
|
|
|
|
recordingsByWork:
|
|
SELECT * FROM recordings WHERE work = :id;
|
|
|
|
performancesByRecording:
|
|
SELECT * FROM performances WHERE recording = :id; |