mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
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:
parent
00def5382e
commit
e0fc60f9eb
3 changed files with 72 additions and 12 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue