mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add basic database for works and composers
This includes tables for persons, instruments and works as well as some queries and functions to work with them. The generated code should be ignored by Git for now. I also added a section to README.md explaining how to handle code generation.
This commit is contained in:
parent
2be7238a96
commit
437e30933a
4 changed files with 102 additions and 0 deletions
40
lib/database.dart
Normal file
40
lib/database.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import 'package:moor_flutter/moor_flutter.dart';
|
||||
|
||||
part 'database.g.dart';
|
||||
|
||||
@UseMoor(
|
||||
include: {
|
||||
'database.moor',
|
||||
},
|
||||
)
|
||||
class Database extends _$Database {
|
||||
Database(String fileName)
|
||||
: super(FlutterQueryExecutor.inDatabaseFolder(path: fileName));
|
||||
|
||||
@override
|
||||
int get schemaVersion => 0;
|
||||
|
||||
Future<void> updatePerson(Person person) async {
|
||||
await into(persons).insert(person);
|
||||
}
|
||||
|
||||
Future<void> updateInstrument(Instrument instrument) async {
|
||||
await into(instruments).insert(instrument);
|
||||
}
|
||||
|
||||
Future<void> updateWork(Work work, List<int> instrumentIds) async {
|
||||
await transaction(() async {
|
||||
await into(works).insert(work);
|
||||
|
||||
await (delete(instrumentations)..where((i) => i.work.equals(work.id)))
|
||||
.go();
|
||||
|
||||
await into(instrumentations).insertAll(instrumentIds
|
||||
.map((id) => Instrumentation(
|
||||
work: work.id,
|
||||
instrument: id,
|
||||
))
|
||||
.toList());
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue