Skip to content

Commit 12b4b88

Browse files
committed
Update sqlite3_web to 0.8.0
1 parent 2ea7aa3 commit 12b4b88

8 files changed

Lines changed: 93 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Compile web worker
2626
run: |
2727
dart pub get
28-
dart compile js -O4 -o assets/db_worker.js packages/sqlite_async/lib/src/web/worker/worker.dart
28+
dart compile js -O4 -Dsqlite3.dartbigints=false -o assets/db_worker.js packages/sqlite_async/lib/src/web/worker/worker.dart
2929
3030
- name: Set tag name
3131
id: tag

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Setup
9393
run: |
9494
dart run tool/sqlite3_wasm_download.dart
95-
dart compile js -O4 --no-minify -o assets/db_worker.js packages/sqlite_async/lib/src/web/worker/worker.dart
95+
dart compile js -O4 --no-minify -Dsqlite3.dartbigints=false -o assets/db_worker.js packages/sqlite_async/lib/src/web/worker/worker.dart
9696
9797
- name: Test sqlite_async
9898
working-directory: packages/sqlite_async

packages/sqlite_async/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.14.2
2+
3+
- Support versions `0.8.x` of `package:sqlite3_web`.
4+
15
## 0.14.1
26

37
- Fix update notifications sometimes firing before a write has completed.

packages/sqlite_async/lib/src/utils/profiler.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ extension TimeSync on TimelineTask? {
5555
if (parameters != null)
5656
'parameters': [
5757
for (final parameter in parameters)
58-
if (parameter is List) '<blob>' else parameter
58+
switch (parameter) {
59+
List() => '<blob>',
60+
BigInt() => parameter.toString(),
61+
_ => parameter,
62+
}
5963
],
6064
}
6165
);

packages/sqlite_async/lib/src/web/web_sqlite_open_factory.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ base class WebSqliteOpenFactory extends InternalOpenFactory {
4545
/// when provided with the same [options] again.
4646
Future<WebSqlite> openWebSqlite(WebSqliteOptions options) async {
4747
return WebSqlite.open(
48-
wasmModule: Uri.parse(sqliteOptions.webSqliteOptions.wasmUri),
48+
wasmModule: sqliteOptions.webSqliteOptions.wasmUri,
4949
workers: WorkerConnector.defaultWorkers(
50-
Uri.parse(sqliteOptions.webSqliteOptions.workerUri)),
50+
sqliteOptions.webSqliteOptions.workerUri),
5151
controller: AsyncSqliteController(),
5252
handleCustomRequest: handleCustomRequest,
5353
);

packages/sqlite_async/lib/src/web/worker/worker.dart

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
/// This is an example of a database worker script
2-
/// Custom database logic can be achieved by implementing this template
3-
/// This file needs to be compiled to JavaScript with the command:
4-
/// dart compile js -O4 lib/src/web/worker/db_worker.dart -o build/db_worker.js
5-
/// The output should then be included in each project's `web` directory
2+
/// Custom database logic can be achieved by implementing this template.
3+
///
4+
/// This file needs to be compiled to JavaScript via `dart compile js`:
5+
///
6+
/// ```
7+
/// dart compile js \
8+
/// lib/src/web/worker/db_worker.dart \
9+
/// -o build/db_worker.js \
10+
/// -O4
11+
/// -Dsqlite3.dartbigints=false
12+
/// ```
13+
///
14+
/// The output should then be included in each project's `web` directory.
15+
///
16+
/// Disabling `sqlite3.dartbigints` as a compile-time option reduces the size of
17+
/// the worker by disabling support for [BigInt] values which are implemented in
18+
/// Dart. The worker still supports native JavaScript bigint values, so this
19+
/// doesn't affect functionality.
620
library;
721

822
import 'package:sqlite3_web/sqlite3_web.dart';

packages/sqlite_async/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sqlite_async
22
description: High-performance asynchronous interface for SQLite on Dart and Flutter.
3-
version: 0.14.1
3+
version: 0.14.2
44
resolution: workspace
55
repository: https://github.com/powersync-ja/sqlite_async.dart
66
environment:
@@ -14,7 +14,7 @@ topics:
1414

1515
dependencies:
1616
sqlite3: ^3.2.0
17-
sqlite3_web: ^0.7.0
17+
sqlite3_web: ^0.8.0
1818
sqlite3_connection_pool: ^0.2.4
1919
async: ^2.10.0
2020
collection: ^1.17.0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
@TestOn('browser')
2+
library;
3+
4+
import 'dart:async';
5+
import 'dart:math';
6+
import 'dart:typed_data';
7+
import 'package:test/test.dart';
8+
9+
import '../utils/test_utils_impl.dart';
10+
11+
const _isDart2Wasm = bool.fromEnvironment('dart.tool.dart2wasm');
12+
final testUtils = TestUtils();
13+
14+
void main() {
15+
group('Web database tests', () {
16+
late String path;
17+
18+
setUp(() async {
19+
path = testUtils.dbPath();
20+
await testUtils.cleanDb(path: path);
21+
});
22+
23+
tearDown(() async {
24+
await testUtils.cleanDb(path: path);
25+
});
26+
27+
test('can bind all types', () async {
28+
final db = await testUtils.setupDatabase(path: path);
29+
addTearDown(db.close);
30+
31+
Future<void> assertTypeOf(Object? value, String typeName) async {
32+
final row = await db.get('SELECT typeof(?)', [value]);
33+
expect(row.values[0], typeName);
34+
}
35+
36+
await assertTypeOf(null, 'null');
37+
await assertTypeOf('hello web', 'text');
38+
await assertTypeOf(Uint8List(12), 'blob');
39+
await assertTypeOf(2, 'integer');
40+
await assertTypeOf(BigInt.two, 'integer');
41+
await assertTypeOf(BigInt.one << 62, 'integer');
42+
await assertTypeOf(pi, 'real');
43+
});
44+
45+
test('large integers are read as bigints on JS', () async {
46+
final db = await testUtils.setupDatabase(path: path);
47+
addTearDown(db.close);
48+
49+
final value = (await db.get('SELECT 1 << 62')).values[0];
50+
if (_isDart2Wasm) {
51+
// We have 64bit ints on dart2wasm, which should be used here.
52+
expect(value, isA<int>());
53+
expect(value, 1 << 62);
54+
} else {
55+
expect(value, isA<BigInt>());
56+
expect(value, BigInt.parse('4611686018427387904'));
57+
}
58+
});
59+
});
60+
}

0 commit comments

Comments
 (0)