Don't sync in transactions, remove interface

This commit is contained in:
Simon Binder 2022-05-23 12:11:06 +02:00
parent 0a37736d1b
commit e2622517a5
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 15 additions and 16 deletions

View File

@ -1,5 +1,6 @@
@internal
import 'package:drift/src/sqlite3/persistence_handler.dart';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:sqlite3/common.dart';
@ -48,6 +49,12 @@ abstract class Sqlite3Delegate<DB extends CommonDatabase>
@override
Future<bool> get isOpen => Future.value(_isOpen);
/// Flush pending writes to the file system on platforms where that is
/// necessary.
///
/// At the moment, we only support this for the WASM backend.
FutureOr<void> flush() => null;
@override
Future<void> open(QueryExecutorUser db) async {
if (!_hasCreatedDatabase) {
@ -89,8 +96,8 @@ abstract class Sqlite3Delegate<DB extends CommonDatabase>
stmt.dispose();
}
if (this is PersistenceHandler) {
await (this as PersistenceHandler).flush();
if (!isInTransaction) {
await flush();
}
return Future.value();
@ -105,8 +112,8 @@ abstract class Sqlite3Delegate<DB extends CommonDatabase>
stmt.dispose();
}
if (this is PersistenceHandler) {
await (this as PersistenceHandler).flush();
if (!isInTransaction) {
await flush();
}
}
@ -141,9 +148,8 @@ abstract class Sqlite3Delegate<DB extends CommonDatabase>
if (_closeUnderlyingWhenClosed) {
beforeClose(_db);
_db.dispose();
if (this is PersistenceHandler) {
await (this as PersistenceHandler).flush();
}
await flush();
}
}
}

View File

@ -1,5 +0,0 @@
///
abstract class PersistenceHandler {
///
Future<void> flush();
}

View File

@ -14,7 +14,6 @@
@experimental
library drift.wasm;
import 'package:drift/src/sqlite3/persistence_handler.dart';
import 'package:meta/meta.dart';
import 'package:sqlite3/common.dart';
import 'package:sqlite3/wasm.dart';
@ -67,8 +66,7 @@ class WasmDatabase extends DelegatedDatabase {
}
}
class _WasmDelegate extends Sqlite3Delegate<CommonDatabase>
implements PersistenceHandler {
class _WasmDelegate extends Sqlite3Delegate<CommonDatabase> {
final CommmonSqlite3 _sqlite3;
final String? _path;
final IndexedDbFileSystem? _fileSystem;