mirror of https://github.com/AMT-Cheif/drift.git
Fix bug with VmDatabase.opened
This commit is contained in:
parent
42ba773422
commit
1edcc634b1
|
@ -108,6 +108,8 @@ class VmDatabase extends DelegatedDatabase {
|
|||
|
||||
class _VmDelegate extends DatabaseDelegate {
|
||||
late Database _db;
|
||||
|
||||
bool _hasCreatedDatabase = false;
|
||||
bool _isOpen = false;
|
||||
|
||||
final File? file;
|
||||
|
@ -115,7 +117,9 @@ class _VmDelegate extends DatabaseDelegate {
|
|||
|
||||
_VmDelegate(this.file, this.setup);
|
||||
|
||||
_VmDelegate._opened(this._db, this.setup) : file = null {
|
||||
_VmDelegate._opened(this._db, this.setup)
|
||||
: file = null,
|
||||
_hasCreatedDatabase = true {
|
||||
_initializeDatabase();
|
||||
}
|
||||
|
||||
|
@ -130,16 +134,18 @@ class _VmDelegate extends DatabaseDelegate {
|
|||
|
||||
@override
|
||||
Future<void> open(QueryExecutorUser user) async {
|
||||
if (!_isOpen) {
|
||||
if (!_hasCreatedDatabase) {
|
||||
_createDatabase();
|
||||
_initializeDatabase();
|
||||
}
|
||||
_initializeDatabase();
|
||||
|
||||
_isOpen = true;
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
void _createDatabase() {
|
||||
assert(!_isOpen);
|
||||
assert(!_hasCreatedDatabase);
|
||||
_hasCreatedDatabase = true;
|
||||
|
||||
final file = this.file;
|
||||
if (file != null) {
|
||||
|
|
|
@ -33,6 +33,9 @@ void main() {
|
|||
final row = await db.customSelect('SELECT my_function() AS r;').getSingle();
|
||||
expect(row!.readString('r'), 'hello from Dart');
|
||||
|
||||
final nativeRow = existing.select('SELECT my_function() AS r;').single;
|
||||
expect(nativeRow['r'], 'hello from Dart');
|
||||
|
||||
await db.close();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue