mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
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.
40 lines
968 B
Dart
40 lines
968 B
Dart
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());
|
|
});
|
|
}
|
|
}
|