Add recordings

The tables ensembles, roles, recordings and performances as well as
corresponding queries and update logic have been added to the database.
This commit is contained in:
Elias Projahn 2020-03-22 14:49:40 +01:00
parent 554cf4a6ac
commit 4092a91f56
2 changed files with 66 additions and 5 deletions

View file

@ -30,11 +30,10 @@ class Database extends _$Database {
int get schemaVersion => 1; int get schemaVersion => 1;
@override @override
MigrationStrategy get migration => MigrationStrategy( MigrationStrategy get migration =>
beforeOpen: (details) async { MigrationStrategy(beforeOpen: (details) async {
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. // TODO: Remove this once https://github.com/simolus3/moor/issues/453 is fixed.
Selectable<Work> worksByComposer(int id) { Selectable<Work> worksByComposer(int id) {
@ -74,4 +73,23 @@ class Database extends _$Database {
} }
}); });
} }
Future<void> updateEnsemble(Ensemble ensemble) async {
await into(ensembles).insert(ensemble, orReplace: true);
}
Future<void> updateRole(Role role) async {
await into(roles).insert(role, orReplace: true);
}
Future<void> updateRecording(
Recording recording, List<Performance> perfs) async {
await transaction(() async {
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);
}
});
}
} }

View file

@ -23,6 +23,28 @@ CREATE TABLE instrumentations (
instrument INTEGER NOT NULL REFERENCES instruments(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: allPersons:
SELECT * FROM persons ORDER BY last_name; SELECT * FROM persons ORDER BY last_name;
@ -50,3 +72,24 @@ instrumentsByWork:
SELECT instruments.* FROM instrumentations SELECT instruments.* FROM instrumentations
JOIN instruments ON instrumentations.instrument=instruments.id JOIN instruments ON instrumentations.instrument=instruments.id
WHERE instrumentations.work = :workId; 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;