Skip to content

Commit 9cea1d2

Browse files
committed
Format sqlite3_web
1 parent 1d287a4 commit 9cea1d2

File tree

4 files changed

+86
-47
lines changed

4 files changed

+86
-47
lines changed

sqlite3_web/lib/src/locks.dart

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ final class DatabaseLocks {
8585
}
8686

8787
Future<T> lock<T>(
88-
FutureOr<T> Function() criticalSection, AbortSignal? abortSignal) async {
88+
FutureOr<T> Function() criticalSection,
89+
AbortSignal? abortSignal,
90+
) async {
8991
if (needsInterContextLocks) {
90-
final held =
91-
await WebLocks.instance!.request(lockName, abortSignal: abortSignal);
92+
final held = await WebLocks.instance!.request(
93+
lockName,
94+
abortSignal: abortSignal,
95+
);
9296
return Future(criticalSection).whenComplete(held.release);
9397
}
9498

@@ -134,19 +138,20 @@ final class Mutex {
134138
}
135139

136140
late StreamSubscription<void> abortSubscription;
137-
abortSubscription =
138-
EventStreamProviders.abortEvent.forTarget(abort).listen((_) {
139-
abortSubscription.cancel();
140-
141-
if (!completer.isCompleted) {
142-
final didRemove = _waiting.remove(complete);
143-
144-
// The only way for waiters to get removed is for [complete] to get
145-
// called, so we wouldn't enter this branch.
146-
assert(didRemove);
147-
completer.completeError(const AbortException());
148-
}
149-
});
141+
abortSubscription = EventStreamProviders.abortEvent
142+
.forTarget(abort)
143+
.listen((_) {
144+
abortSubscription.cancel();
145+
146+
if (!completer.isCompleted) {
147+
final didRemove = _waiting.remove(complete);
148+
149+
// The only way for waiters to get removed is for [complete] to get
150+
// called, so we wouldn't enter this branch.
151+
assert(didRemove);
152+
completer.completeError(const AbortException());
153+
}
154+
});
150155

151156
_waiting.addLast(complete);
152157
return completer.future.whenComplete(markCompleted);

sqlite3_web/lib/src/types.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ enum DatabaseImplementation {
5353
/// There is no concurrency control between these tabs, so this effectively
5454
/// does not support multiple tabs. It's mostly included for legacy reasons.
5555
indexedDbUnsafeWorker(
56-
StorageMode.indexedDb, AccessMode.throughDedicatedWorker),
56+
StorageMode.indexedDb,
57+
AccessMode.throughDedicatedWorker,
58+
),
5759

5860
/// Open an IndexedDB database in a shared worker.
5961
indexedDbShared(StorageMode.indexedDb, AccessMode.throughSharedWorker),
@@ -74,8 +76,7 @@ enum DatabaseImplementation {
7476
///
7577
/// This works by letting a shared worker spawn a dedicated worker. This is
7678
/// supposed to work, but only implemented in Firefox.
77-
opfsShared(StorageMode.opfs, AccessMode.throughSharedWorker),
78-
;
79+
opfsShared(StorageMode.opfs, AccessMode.throughSharedWorker);
7980

8081
final StorageMode storage;
8182
final AccessMode access;

sqlite3_web/test/asset_server.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Middleware cors() {
2222
}
2323

2424
return createMiddleware(
25-
requestHandler: handleOptionsRequest, responseHandler: addCorsHeaders);
25+
requestHandler: handleOptionsRequest,
26+
responseHandler: addCorsHeaders,
27+
);
2628
}
2729

2830
Future<void> hybridMain(StreamChannel<Object?> channel) async {

sqlite3_web/test/worker_test.dart

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ void main() {
4242
}
4343

4444
Future<RemoteDatabase> requestDatabase(
45-
String name, DatabaseImplementation implementation) async {
45+
String name,
46+
DatabaseImplementation implementation,
47+
) async {
4648
final conn = await connectTo(localEnv);
4749
return await conn.requestDatabase(
4850
wasmUri: sqlite3WasmUri,
@@ -54,41 +56,53 @@ void main() {
5456
}
5557

5658
test('can open database', () async {
57-
final db =
58-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
59+
final db = await requestDatabase(
60+
'foo',
61+
DatabaseImplementation.inMemoryShared,
62+
);
5963

6064
final results = await db.select('SELECT 1 as r;');
6165
expect(results.result, [
62-
{'r': 1}
66+
{'r': 1},
6367
]);
6468
});
6569

6670
test('can share database between clients', () async {
67-
final a =
68-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
69-
final b =
70-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
71+
final a = await requestDatabase(
72+
'foo',
73+
DatabaseImplementation.inMemoryShared,
74+
);
75+
final b = await requestDatabase(
76+
'foo',
77+
DatabaseImplementation.inMemoryShared,
78+
);
7179
await a.execute('CREATE TABLE foo (bar TEXT);');
7280
await b.execute('INSERT INTO foo DEFAULT VALUES');
7381
final results = await a.select('SELECT * FROM foo');
7482
expect(results.result, hasLength(1));
7583
});
7684

7785
test('releases resources for closed databases', () async {
78-
final a =
79-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
86+
final a = await requestDatabase(
87+
'foo',
88+
DatabaseImplementation.inMemoryShared,
89+
);
8090
await a.execute('CREATE TABLE foo (bar TEXT);');
8191
await a.dispose();
8292

83-
final b =
84-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
93+
final b = await requestDatabase(
94+
'foo',
95+
DatabaseImplementation.inMemoryShared,
96+
);
8597
// This would fail if the in-memory database were reused.
8698
await b.execute('CREATE TABLE foo (bar TEXT);');
8799
});
88100

89101
test('returns autocommit state', () async {
90-
final a =
91-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
102+
final a = await requestDatabase(
103+
'foo',
104+
DatabaseImplementation.inMemoryShared,
105+
);
92106
var res = await a.execute('BEGIN');
93107
expect(res.autocommit, isFalse);
94108

@@ -97,18 +111,24 @@ void main() {
97111
});
98112

99113
test('returns last insert rowid', () async {
100-
final a =
101-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
114+
final a = await requestDatabase(
115+
'foo',
116+
DatabaseImplementation.inMemoryShared,
117+
);
102118
await a.execute('CREATE TABLE foo (bar TEXT);');
103119

104-
final insert = await a
105-
.execute('INSERT INTO foo (bar) VALUES (?)', parameters: ['test']);
120+
final insert = await a.execute(
121+
'INSERT INTO foo (bar) VALUES (?)',
122+
parameters: ['test'],
123+
);
106124
expect(insert.lastInsertRowid, 1);
107125
});
108126

109127
test('check in transaction', () async {
110-
final a =
111-
await requestDatabase('foo', DatabaseImplementation.inMemoryShared);
128+
final a = await requestDatabase(
129+
'foo',
130+
DatabaseImplementation.inMemoryShared,
131+
);
112132
await a.execute('CREATE TABLE foo (bar TEXT);');
113133

114134
await a.execute('BEGIN');
@@ -119,8 +139,10 @@ void main() {
119139
);
120140
await a.execute('COMMIT');
121141

122-
await expectLater(a.execute('SELECT 1', checkInTransaction: true),
123-
throwsA(isA<RemoteException>()));
142+
await expectLater(
143+
a.execute('SELECT 1', checkInTransaction: true),
144+
throwsA(isA<RemoteException>()),
145+
);
124146
});
125147

126148
group('locks', () {
@@ -162,7 +184,8 @@ void main() {
162184
await a.requestLock((token) async {
163185
// The token needs to be passed for statements to work.
164186
queryResult.complete(
165-
a.select('SELECT 1').whenComplete(() => hasResults = true));
187+
a.select('SELECT 1').whenComplete(() => hasResults = true),
188+
);
166189
expect(hasResults, isFalse);
167190
await pumpEventQueue();
168191
expect(hasResults, isFalse);
@@ -263,13 +286,19 @@ void main() {
263286
final class _TestController extends DatabaseController {
264287
@override
265288
Future<JSAny?> handleCustomRequest(
266-
ClientConnection connection, JSAny? request) {
289+
ClientConnection connection,
290+
JSAny? request,
291+
) {
267292
throw UnimplementedError();
268293
}
269294

270295
@override
271-
Future<WorkerDatabase> openDatabase(WasmSqlite3 sqlite3, String path,
272-
String vfs, JSAny? additionalData) async {
296+
Future<WorkerDatabase> openDatabase(
297+
WasmSqlite3 sqlite3,
298+
String path,
299+
String vfs,
300+
JSAny? additionalData,
301+
) async {
273302
return _TestDatabase(sqlite3.open(path, vfs: vfs));
274303
}
275304
}
@@ -282,7 +311,9 @@ final class _TestDatabase extends WorkerDatabase {
282311

283312
@override
284313
Future<JSAny?> handleCustomRequest(
285-
ClientConnection connection, JSAny? request) {
314+
ClientConnection connection,
315+
JSAny? request,
316+
) {
286317
throw UnimplementedError();
287318
}
288319
}

0 commit comments

Comments
 (0)