37 lines
929 B
Dart
37 lines
929 B
Dart
import 'dart:io';
|
|
|
|
import 'package:fmassive/gym_set.dart';
|
|
import 'package:moor/ffi.dart';
|
|
import 'package:moor/moor.dart';
|
|
import 'package:path/path.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'settings.dart';
|
|
|
|
part 'database.g.dart';
|
|
|
|
@UseMoor(tables: [Settings, GymSets])
|
|
class MyDatabase extends _$MyDatabase {
|
|
MyDatabase() : super(_openConnection());
|
|
|
|
@override
|
|
int get schemaVersion => 1;
|
|
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onCreate: (Migrator m) async {
|
|
await m.createAll();
|
|
},
|
|
onUpgrade: (Migrator m, int from, int to) async {
|
|
// no migrations yet
|
|
},
|
|
);
|
|
}
|
|
|
|
LazyDatabase _openConnection() {
|
|
return LazyDatabase(() async {
|
|
final dbFolder = await getApplicationDocumentsDirectory();
|
|
final file = File(join(dbFolder.path, 'massive.db'));
|
|
return VmDatabase(file, logStatements: true);
|
|
});
|
|
}
|