File tree Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ class _ExclusiveTransactionContext extends _ExclusiveContext {
212
212
@override
213
213
Future <ResultSet > execute (String sql,
214
214
[List <Object ?> parameters = const []]) async {
215
+ // TODO offload this to a custom request for single round trip
215
216
final isAutoCommit = await getAutoCommit ();
216
217
if (isAutoCommit && ! sql.toLowerCase ().contains ('begin' )) {
217
218
throw SqliteException (0 ,
@@ -223,6 +224,7 @@ class _ExclusiveTransactionContext extends _ExclusiveContext {
223
224
@override
224
225
Future <void > executeBatch (
225
226
String sql, List <List <Object ?>> parameterSets) async {
227
+ // TODO offload this to a custom request for single round trip
226
228
final isAutoCommit = await getAutoCommit ();
227
229
if (isAutoCommit && ! sql.toLowerCase ().contains ('begin' )) {
228
230
throw SqliteException (0 ,
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ class SqliteDatabaseImpl
21
21
return _connection.closed;
22
22
}
23
23
24
+ final StreamController <UpdateNotification > updatesController =
25
+ StreamController .broadcast ();
26
+
24
27
@override
25
28
late Stream <UpdateNotification > updates;
26
29
@@ -68,13 +71,17 @@ class SqliteDatabaseImpl
68
71
SqliteDatabaseImpl .withFactory (this .openFactory,
69
72
{this .maxReaders = SqliteDatabase .defaultMaxReaders}) {
70
73
mutex = MutexImpl ();
74
+ // This way the `updates` member is available synchronously
75
+ updates = updatesController.stream;
71
76
isInitialized = _init ();
72
77
}
73
78
74
79
Future <void > _init () async {
75
80
_connection = await openFactory.openConnection (SqliteOpenOptions (
76
81
primaryConnection: true , readOnly: false , mutex: mutex));
77
- updates = _connection.updates! ;
82
+ _connection.updates! .forEach ((update) {
83
+ updatesController.add (update);
84
+ });
78
85
}
79
86
80
87
T _runZoned <T >(T Function () callback, {required String debugContext}) {
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import 'package:sqlite_async/src/web/web_mutex.dart';
7
7
8
8
import 'database.dart' ;
9
9
10
- Map <SqliteOptions , WebSqlite > webSQLiteImplementations = {};
10
+ Map <String , FutureOr < WebSqlite > > webSQLiteImplementations = {};
11
11
12
12
/// Web implementation of [AbstractDefaultSqliteOpenFactory]
13
13
class DefaultSqliteOpenFactory
@@ -20,15 +20,18 @@ class DefaultSqliteOpenFactory
20
20
{required super .path,
21
21
super .sqliteOptions = const SqliteOptions .defaults ()})
22
22
: _initialized = Future .sync (() {
23
- if (webSQLiteImplementations.containsKey (sqliteOptions)) {
24
- return webSQLiteImplementations[sqliteOptions]! ;
23
+ final cacheKey = sqliteOptions.webSqliteOptions.wasmUri +
24
+ sqliteOptions.webSqliteOptions.workerUri;
25
+
26
+ if (webSQLiteImplementations.containsKey (cacheKey)) {
27
+ return webSQLiteImplementations[cacheKey]! ;
25
28
}
26
29
27
- webSQLiteImplementations[sqliteOptions ] = WebSqlite .open (
30
+ webSQLiteImplementations[cacheKey ] = WebSqlite .open (
28
31
wasmModule: Uri .parse (sqliteOptions.webSqliteOptions.wasmUri),
29
32
worker: Uri .parse (sqliteOptions.webSqliteOptions.workerUri),
30
33
);
31
- return webSQLiteImplementations[sqliteOptions ]! ;
34
+ return webSQLiteImplementations[cacheKey ]! ;
32
35
});
33
36
34
37
@override
Original file line number Diff line number Diff line change 1
1
import 'dart:js_interop' ;
2
- import 'dart:js_interop_unsafe' ;
3
2
4
3
import 'package:mutex/mutex.dart' ;
5
4
import 'package:sqlite3/wasm.dart' ;
@@ -8,7 +7,7 @@ import 'package:sqlite_async/sqlite3_common.dart';
8
7
9
8
import '../protocol.dart' ;
10
9
11
- final class AsyncSqliteController extends DatabaseController {
10
+ base class AsyncSqliteController extends DatabaseController {
12
11
@override
13
12
Future <WorkerDatabase > openDatabase (
14
13
WasmSqlite3 sqlite3, String path, String vfs) async {
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ void main() {
38
38
'INSERT INTO test_data(description) VALUES(?)' , ['test' ]);
39
39
}, throwsA ((e) => e is LockError && e.message.contains ('tx.execute' )));
40
40
});
41
+ // Uncomment this to break this test
42
+ // await db.close();
41
43
});
42
44
43
45
test ('should allow PRAMGAs' , () async {
You can’t perform that action at this time.
0 commit comments