mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-04 02:59:16 -05:00
39 lines
928 B
Dart
39 lines
928 B
Dart
import 'dart:io';
|
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
import 'unsupported.dart' if (dart.library.ffi) 'native.dart' if (dart.library.html) 'web.dart';
|
|
|
|
part 'db.g.dart';
|
|
|
|
@DriftDatabase(include: {
|
|
'resources.drift',
|
|
})
|
|
class AppDatabase extends _$AppDatabase {
|
|
static Directory? storageDir;
|
|
static Directory? tmpDir;
|
|
final String id;
|
|
|
|
AppDatabase({required this.id}) : super(_openConnection(id));
|
|
|
|
@override
|
|
int get schemaVersion => 11;
|
|
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onCreate: (m) => m.createAll(),
|
|
onUpgrade: (m, from, to) async {
|
|
await m.drop(resources);
|
|
await m.createAll();
|
|
});
|
|
|
|
Future<void> dropDatabase() async {
|
|
await super.close();
|
|
await deleteDatabase(storageDir: storageDir, id: id);
|
|
}
|
|
|
|
static QueryExecutor _openConnection(String id) {
|
|
return openDatabase(storageDir: storageDir, tmpDir: tmpDir, id: id);
|
|
}
|
|
}
|