Run Moor within a background isolate

This basically follows the guidelines at
https://moor.simonbinder.eu/docs/advanced-features/isolates/. In the
future we will be able to have multiple simultaneous database
connections.
This commit is contained in:
Elias Projahn 2020-04-17 17:25:25 +02:00
parent 00def5382e
commit e0fc60f9eb
3 changed files with 72 additions and 12 deletions

View file

@ -1,10 +1,6 @@
import 'dart:io';
import 'dart:math';
import 'package:moor/moor.dart';
import 'package:moor_ffi/moor_ffi.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart' as pp;
part 'database.g.dart';
@ -38,13 +34,8 @@ class PerformanceModel {
'database.moor',
},
)
class Database extends _$Database {
Database(String fileName)
: super(LazyDatabase(() async {
final dir = await pp.getApplicationDocumentsDirectory();
final file = File(p.join(dir.path, fileName));
return VmDatabase(file);
}));
class Database extends _$Database {
Database.connect(DatabaseConnection connection) : super.connect(connection);
@override
int get schemaVersion => 1;