@livestore/wa-sqlite 0.4.0-dev.22 → 0.4.0-dev.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +46 -36
  2. package/dist/README.md +13 -13
  3. package/dist/fts5/wa-sqlite.mjs +1 -1
  4. package/dist/fts5/wa-sqlite.node.mjs +1 -1
  5. package/dist/fts5/wa-sqlite.node.wasm +0 -0
  6. package/dist/fts5/wa-sqlite.wasm +0 -0
  7. package/dist/wa-sqlite-async.mjs +1 -1
  8. package/dist/wa-sqlite-async.wasm +0 -0
  9. package/dist/wa-sqlite-jspi.mjs +1 -1
  10. package/dist/wa-sqlite-jspi.wasm +0 -0
  11. package/dist/wa-sqlite.mjs +1 -1
  12. package/dist/wa-sqlite.node.mjs +1 -1
  13. package/dist/wa-sqlite.node.wasm +0 -0
  14. package/dist/wa-sqlite.wasm +0 -0
  15. package/package.json +40 -29
  16. package/src/FacadeVFS.js +252 -261
  17. package/src/VFS.js +84 -85
  18. package/src/WebLocksMixin.js +357 -351
  19. package/src/examples/AccessHandlePoolVFS.js +185 -194
  20. package/src/examples/IDBBatchAtomicVFS.js +429 -409
  21. package/src/examples/IDBMirrorVFS.js +402 -409
  22. package/src/examples/MemoryAsyncVFS.js +32 -37
  23. package/src/examples/MemoryVFS.js +71 -75
  24. package/src/examples/OPFSAdaptiveVFS.js +206 -206
  25. package/src/examples/OPFSAnyContextVFS.js +141 -140
  26. package/src/examples/OPFSCoopSyncVFS.js +297 -299
  27. package/src/examples/OPFSPermutedVFS.js +529 -540
  28. package/src/examples/README.md +27 -15
  29. package/src/examples/tag.js +27 -27
  30. package/src/sqlite-api.js +910 -941
  31. package/src/sqlite-constants.js +246 -232
  32. package/src/types/globals.d.ts +52 -52
  33. package/src/types/index.d.ts +586 -576
  34. package/test/AccessHandlePoolVFS.test.js +21 -21
  35. package/test/IDBBatchAtomicVFS.test.js +69 -69
  36. package/test/IDBMirrorVFS.test.js +21 -21
  37. package/test/MemoryAsyncVFS.test.js +21 -21
  38. package/test/MemoryVFS.test.js +21 -21
  39. package/test/OPFSAdaptiveVFS.test.js +21 -21
  40. package/test/OPFSAnyContextVFS.test.js +21 -21
  41. package/test/OPFSCoopSyncVFS.test.js +21 -21
  42. package/test/OPFSPermutedVFS.test.js +21 -21
  43. package/test/TestContext.js +44 -41
  44. package/test/WebLocksMixin.test.js +369 -360
  45. package/test/api.test.js +23 -23
  46. package/test/api_exec.js +72 -61
  47. package/test/api_misc.js +53 -54
  48. package/test/api_statements.js +271 -279
  49. package/test/callbacks.test.js +492 -478
  50. package/test/data/idbv5.json +1135 -1
  51. package/test/sql.test.js +30 -30
  52. package/test/sql_0001.js +49 -33
  53. package/test/sql_0002.js +55 -34
  54. package/test/sql_0003.js +85 -49
  55. package/test/sql_0004.js +76 -47
  56. package/test/sql_0005.js +60 -44
  57. package/test/test-worker.js +171 -163
  58. package/test/vfs_xAccess.js +1 -2
  59. package/test/vfs_xClose.js +50 -49
  60. package/test/vfs_xOpen.js +73 -72
  61. package/test/vfs_xRead.js +31 -31
  62. package/test/vfs_xWrite.js +30 -29
@@ -1,447 +1,439 @@
1
- import * as SQLite from '../src/sqlite-api.js';
1
+ import * as SQLite from '../src/sqlite-api.js'
2
2
 
3
3
  export function api_statements(context) {
4
- describe('statements', function() {
5
- let proxy, sqlite3, db;
6
- beforeEach(async function() {
7
- proxy = await context.create();
8
- sqlite3 = proxy.sqlite3;
9
- db = await sqlite3.open_v2('demo');
10
- });
11
-
12
- afterEach(async function() {
13
- await sqlite3.close(db);
14
- await context.destroy(proxy);
15
- });
16
-
17
- it('should iterate', async function() {
18
- const sql = [
19
- 'PRAGMA journal_mode',
20
- 'CREATE TABLE t(x)',
21
- 'SELECT * FROM sqlite_master'
22
- ];
23
-
24
- let count = 0;
4
+ describe('statements', function () {
5
+ let proxy, sqlite3, db
6
+ beforeEach(async function () {
7
+ proxy = await context.create()
8
+ sqlite3 = proxy.sqlite3
9
+ db = await sqlite3.open_v2('demo')
10
+ })
11
+
12
+ afterEach(async function () {
13
+ await sqlite3.close(db)
14
+ await context.destroy(proxy)
15
+ })
16
+
17
+ it('should iterate', async function () {
18
+ const sql = ['PRAGMA journal_mode', 'CREATE TABLE t(x)', 'SELECT * FROM sqlite_master']
19
+
20
+ let count = 0
25
21
  for await (const stmt of i(sqlite3.statements(db, sql.join(';\n')))) {
26
22
  // We should be able to retrieve each parsed statement.
27
- const query = await sqlite3.sql(stmt);
28
- expect(query.includes(sql[count++])).toBeTrue();
23
+ const query = await sqlite3.sql(stmt)
24
+ expect(query.includes(sql[count++])).toBeTrue()
29
25
  }
30
- expect(count).toEqual(sql.length);
31
- });
26
+ expect(count).toEqual(sql.length)
27
+ })
32
28
 
33
- it('should bind blob', async function() {
34
- let rc;
35
- const sql = 'SELECT ?';
36
- const value = new Uint8Array([1, 2, 3, 4, 5]);
29
+ it('should bind blob', async function () {
30
+ let rc
31
+ const sql = 'SELECT ?'
32
+ const value = new Uint8Array([1, 2, 3, 4, 5])
37
33
 
38
34
  for await (const stmt of i(sqlite3.statements(db, sql))) {
39
- rc = await sqlite3.bind_blob(stmt, 1, value);
40
- expect(rc).toEqual(SQLite.SQLITE_OK);
35
+ rc = await sqlite3.bind_blob(stmt, 1, value)
36
+ expect(rc).toEqual(SQLite.SQLITE_OK)
41
37
 
42
38
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
43
- expect(rc).toEqual(SQLite.SQLITE_ROW);
39
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
44
40
 
45
- expect(await sqlite3.column_count(stmt)).toEqual(1);
46
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_BLOB);
41
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
42
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_BLOB)
47
43
 
48
- const blobTyped = await sqlite3.column_blob(stmt, 0);
49
- expect([...blobTyped]).toEqual([...value]);
44
+ const blobTyped = await sqlite3.column_blob(stmt, 0)
45
+ expect([...blobTyped]).toEqual([...value])
50
46
 
51
- const blobVariant = await sqlite3.column(stmt, 0);
52
- expect([...blobVariant]).toEqual([...value]);
47
+ const blobVariant = await sqlite3.column(stmt, 0)
48
+ expect([...blobVariant]).toEqual([...value])
53
49
  }
54
50
  }
55
51
 
56
52
  for await (const stmt of i(sqlite3.statements(db, sql))) {
57
53
  // Comlink intercepts the 'bind' property so use an alias.
58
- rc = await sqlite3.bind$(stmt, 1, value);
59
- expect(rc).toEqual(SQLite.SQLITE_OK);
54
+ rc = await sqlite3.bind$(stmt, 1, value)
55
+ expect(rc).toEqual(SQLite.SQLITE_OK)
60
56
 
61
57
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
62
- expect(rc).toEqual(SQLite.SQLITE_ROW);
58
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
63
59
 
64
- expect(await sqlite3.column_count(stmt)).toEqual(1);
65
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_BLOB);
60
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
61
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_BLOB)
66
62
 
67
- const blob = await sqlite3.column_blob(stmt, 0);
68
- expect([...blob]).toEqual([...value]);
63
+ const blob = await sqlite3.column_blob(stmt, 0)
64
+ expect([...blob]).toEqual([...value])
69
65
  }
70
66
  }
71
- });
67
+ })
72
68
 
73
- it('should bind double', async function() {
74
- let rc;
75
- const sql = 'SELECT ?';
76
- const value = Math.PI;
69
+ it('should bind double', async function () {
70
+ let rc
71
+ const sql = 'SELECT ?'
72
+ const value = Math.PI
77
73
 
78
74
  for await (const stmt of i(sqlite3.statements(db, sql))) {
79
- rc = await sqlite3.bind_double(stmt, 1, value);
80
- expect(rc).toEqual(SQLite.SQLITE_OK);
75
+ rc = await sqlite3.bind_double(stmt, 1, value)
76
+ expect(rc).toEqual(SQLite.SQLITE_OK)
81
77
 
82
78
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
83
- expect(rc).toEqual(SQLite.SQLITE_ROW);
79
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
84
80
 
85
- expect(await sqlite3.column_count(stmt)).toEqual(1);
86
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_FLOAT);
87
- expect(await sqlite3.column_double(stmt, 0)).toEqual(value);
88
- expect(await sqlite3.column(stmt, 0)).toEqual(value);
81
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
82
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_FLOAT)
83
+ expect(await sqlite3.column_double(stmt, 0)).toEqual(value)
84
+ expect(await sqlite3.column(stmt, 0)).toEqual(value)
89
85
  }
90
86
  }
91
87
 
92
88
  for await (const stmt of i(sqlite3.statements(db, sql))) {
93
89
  // Comlink intercepts the 'bind' property so use an alias.
94
- rc = await sqlite3.bind$(stmt, 1, value);
95
- expect(rc).toEqual(SQLite.SQLITE_OK);
90
+ rc = await sqlite3.bind$(stmt, 1, value)
91
+ expect(rc).toEqual(SQLite.SQLITE_OK)
96
92
 
97
93
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
98
- expect(rc).toEqual(SQLite.SQLITE_ROW);
94
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
99
95
 
100
- expect(await sqlite3.column_count(stmt)).toEqual(1);
101
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_FLOAT);
102
- expect(await sqlite3.column_double(stmt, 0)).toEqual(value);
96
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
97
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_FLOAT)
98
+ expect(await sqlite3.column_double(stmt, 0)).toEqual(value)
103
99
  }
104
100
  }
105
- });
101
+ })
106
102
 
107
- it('should bind int', async function() {
108
- let rc;
109
- const sql = 'SELECT ?';
110
- const value = 42;
103
+ it('should bind int', async function () {
104
+ let rc
105
+ const sql = 'SELECT ?'
106
+ const value = 42
111
107
 
112
108
  for await (const stmt of i(sqlite3.statements(db, sql))) {
113
- rc = await sqlite3.bind_int(stmt, 1, value);
114
- expect(rc).toEqual(SQLite.SQLITE_OK);
109
+ rc = await sqlite3.bind_int(stmt, 1, value)
110
+ expect(rc).toEqual(SQLite.SQLITE_OK)
115
111
 
116
112
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
117
- expect(rc).toEqual(SQLite.SQLITE_ROW);
113
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
118
114
 
119
- expect(await sqlite3.column_count(stmt)).toEqual(1);
120
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
121
- expect(await sqlite3.column_int(stmt, 0)).toEqual(value);
122
- expect(await sqlite3.column(stmt, 0)).toEqual(value);
115
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
116
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER)
117
+ expect(await sqlite3.column_int(stmt, 0)).toEqual(value)
118
+ expect(await sqlite3.column(stmt, 0)).toEqual(value)
123
119
  }
124
120
  }
125
121
 
126
122
  for await (const stmt of i(sqlite3.statements(db, sql))) {
127
123
  // Comlink intercepts the 'bind' property so use an alias.
128
- rc = await sqlite3.bind$(stmt, 1, value);
129
- expect(rc).toEqual(SQLite.SQLITE_OK);
124
+ rc = await sqlite3.bind$(stmt, 1, value)
125
+ expect(rc).toEqual(SQLite.SQLITE_OK)
130
126
 
131
127
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
132
- expect(rc).toEqual(SQLite.SQLITE_ROW);
128
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
133
129
 
134
- expect(await sqlite3.column_count(stmt)).toEqual(1);
135
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
136
- expect(await sqlite3.column_int(stmt, 0)).toEqual(value);
130
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
131
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER)
132
+ expect(await sqlite3.column_int(stmt, 0)).toEqual(value)
137
133
  }
138
134
  }
139
- });
135
+ })
140
136
 
141
- it('should bind int64', async function() {
142
- let rc;
143
- const sql = 'SELECT ?';
144
- const value = BigInt(Number.MAX_SAFE_INTEGER) + 1n;
137
+ it('should bind int64', async function () {
138
+ let rc
139
+ const sql = 'SELECT ?'
140
+ const value = BigInt(Number.MAX_SAFE_INTEGER) + 1n
145
141
 
146
142
  for await (const stmt of i(sqlite3.statements(db, sql))) {
147
- rc = await sqlite3.bind_int64(stmt, 1, value);
148
- expect(rc).toEqual(SQLite.SQLITE_OK);
143
+ rc = await sqlite3.bind_int64(stmt, 1, value)
144
+ expect(rc).toEqual(SQLite.SQLITE_OK)
149
145
 
150
146
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
151
- expect(rc).toEqual(SQLite.SQLITE_ROW);
147
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
152
148
 
153
- expect(await sqlite3.column_count(stmt)).toEqual(1);
154
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
155
- expect(await sqlite3.column_int64(stmt, 0)).toEqual(value);
156
- expect(await sqlite3.column(stmt, 0)).toEqual(value);
149
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
150
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER)
151
+ expect(await sqlite3.column_int64(stmt, 0)).toEqual(value)
152
+ expect(await sqlite3.column(stmt, 0)).toEqual(value)
157
153
  }
158
154
  }
159
155
 
160
156
  for await (const stmt of i(sqlite3.statements(db, sql))) {
161
157
  // Comlink intercepts the 'bind' property so use an alias.
162
- rc = await sqlite3.bind$(stmt, 1, value);
163
- expect(rc).toEqual(SQLite.SQLITE_OK);
158
+ rc = await sqlite3.bind$(stmt, 1, value)
159
+ expect(rc).toEqual(SQLite.SQLITE_OK)
164
160
 
165
161
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
166
- expect(rc).toEqual(SQLite.SQLITE_ROW);
162
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
167
163
 
168
- expect(await sqlite3.column_count(stmt)).toEqual(1);
169
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
170
- expect(await sqlite3.column_int64(stmt, 0)).toEqual(value);
164
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
165
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER)
166
+ expect(await sqlite3.column_int64(stmt, 0)).toEqual(value)
171
167
  }
172
168
  }
173
- });
169
+ })
174
170
 
175
- it('should bind null', async function() {
176
- let rc;
177
- const sql = 'SELECT ?';
171
+ it('should bind null', async function () {
172
+ let rc
173
+ const sql = 'SELECT ?'
178
174
 
179
175
  for await (const stmt of i(sqlite3.statements(db, sql))) {
180
- rc = await sqlite3.bind_null(stmt, 1);
181
- expect(rc).toEqual(SQLite.SQLITE_OK);
182
- await expectAsync(sqlite3.bind_parameter_count(stmt)).toBeResolvedTo(1);
176
+ rc = await sqlite3.bind_null(stmt, 1)
177
+ expect(rc).toEqual(SQLite.SQLITE_OK)
178
+ await expectAsync(sqlite3.bind_parameter_count(stmt)).toBeResolvedTo(1)
183
179
 
184
180
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
185
- expect(rc).toEqual(SQLite.SQLITE_ROW);
181
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
186
182
 
187
- await expectAsync(sqlite3.column_count(stmt)).toBeResolvedTo(1);
188
- await expectAsync(sqlite3.column_type(stmt, 0)).toBeResolvedTo(SQLite.SQLITE_NULL);
189
- await expectAsync(sqlite3.column(stmt, 0)).toBeResolvedTo(null);
183
+ await expectAsync(sqlite3.column_count(stmt)).toBeResolvedTo(1)
184
+ await expectAsync(sqlite3.column_type(stmt, 0)).toBeResolvedTo(SQLite.SQLITE_NULL)
185
+ await expectAsync(sqlite3.column(stmt, 0)).toBeResolvedTo(null)
190
186
  }
191
187
  }
192
188
 
193
189
  for await (const stmt of i(sqlite3.statements(db, sql))) {
194
190
  // Comlink intercepts the 'bind' property so use an alias.
195
- rc = await sqlite3.bind$(stmt, 1, null);
196
- expect(rc).toEqual(SQLite.SQLITE_OK);
191
+ rc = await sqlite3.bind$(stmt, 1, null)
192
+ expect(rc).toEqual(SQLite.SQLITE_OK)
197
193
 
198
194
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
199
- expect(rc).toEqual(SQLite.SQLITE_ROW);
195
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
200
196
 
201
- await expectAsync(sqlite3.column_count(stmt)).toBeResolvedTo(1);
202
- await expectAsync(sqlite3.column_type(stmt, 0)).toBeResolvedTo(SQLite.SQLITE_NULL);
197
+ await expectAsync(sqlite3.column_count(stmt)).toBeResolvedTo(1)
198
+ await expectAsync(sqlite3.column_type(stmt, 0)).toBeResolvedTo(SQLite.SQLITE_NULL)
203
199
  }
204
200
  }
205
- });
201
+ })
206
202
 
207
- it('should bind text', async function() {
208
- let rc;
209
- const sql = 'SELECT ?';
210
- const value = 'Hello, world!';
203
+ it('should bind text', async function () {
204
+ let rc
205
+ const sql = 'SELECT ?'
206
+ const value = 'Hello, world!'
211
207
 
212
208
  for await (const stmt of i(sqlite3.statements(db, sql))) {
213
- rc = await sqlite3.bind_text(stmt, 1, value);
214
- expect(rc).toEqual(SQLite.SQLITE_OK);
209
+ rc = await sqlite3.bind_text(stmt, 1, value)
210
+ expect(rc).toEqual(SQLite.SQLITE_OK)
215
211
 
216
212
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
217
- expect(rc).toEqual(SQLite.SQLITE_ROW);
213
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
218
214
 
219
- expect(await sqlite3.column_count(stmt)).toEqual(1);
220
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_TEXT);
221
- expect(await sqlite3.column_text(stmt, 0)).toEqual(value);
222
- expect(await sqlite3.column(stmt, 0)).toEqual(value);
215
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
216
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_TEXT)
217
+ expect(await sqlite3.column_text(stmt, 0)).toEqual(value)
218
+ expect(await sqlite3.column(stmt, 0)).toEqual(value)
223
219
  }
224
220
  }
225
221
 
226
222
  for await (const stmt of i(sqlite3.statements(db, sql))) {
227
223
  // Comlink intercepts the 'bind' property so use an alias.
228
- rc = await sqlite3.bind$(stmt, 1, value);
229
- expect(rc).toEqual(SQLite.SQLITE_OK);
224
+ rc = await sqlite3.bind$(stmt, 1, value)
225
+ expect(rc).toEqual(SQLite.SQLITE_OK)
230
226
 
231
227
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
232
- expect(rc).toEqual(SQLite.SQLITE_ROW);
228
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
233
229
 
234
- expect(await sqlite3.column_count(stmt)).toEqual(1);
235
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_TEXT);
236
- expect(await sqlite3.column_text(stmt, 0)).toEqual(value);
230
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
231
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_TEXT)
232
+ expect(await sqlite3.column_text(stmt, 0)).toEqual(value)
237
233
  }
238
234
  }
239
- });
235
+ })
240
236
 
241
- it('should bind boolean', async function() {
242
- let rc;
243
- const sql = 'SELECT ?';
244
- const storeValue = true;
245
- const expectedRetrievedValue = 1;
237
+ it('should bind boolean', async function () {
238
+ let rc
239
+ const sql = 'SELECT ?'
240
+ const storeValue = true
241
+ const expectedRetrievedValue = 1
246
242
 
247
243
  for await (const stmt of i(sqlite3.statements(db, sql))) {
248
244
  // Comlink intercepts the 'bind' property so use an alias.
249
- rc = await sqlite3.bind$(stmt, 1, storeValue);
250
- expect(rc).toEqual(SQLite.SQLITE_OK);
245
+ rc = await sqlite3.bind$(stmt, 1, storeValue)
246
+ expect(rc).toEqual(SQLite.SQLITE_OK)
251
247
 
252
248
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
253
- expect(rc).toEqual(SQLite.SQLITE_ROW);
249
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
254
250
 
255
- expect(await sqlite3.column_count(stmt)).toEqual(1);
256
- expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER);
257
- expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue);
251
+ expect(await sqlite3.column_count(stmt)).toEqual(1)
252
+ expect(await sqlite3.column_type(stmt, 0)).toEqual(SQLite.SQLITE_INTEGER)
253
+ expect(await sqlite3.column_int(stmt, 0)).toEqual(expectedRetrievedValue)
258
254
  }
259
255
  }
260
- });
256
+ })
261
257
 
262
- it('should bind collection array', async function() {
263
- let rc;
264
- const sql = 'VALUES (?, ?, ?, ?, ?)';
265
- const cBlob = new Uint8Array([8, 6, 7, 5, 3, 0, 9]);
266
- const cDouble = Math.PI;
267
- const cInt = 42;
268
- const cNull = null;
269
- const cText = 'foobar';
258
+ it('should bind collection array', async function () {
259
+ let rc
260
+ const sql = 'VALUES (?, ?, ?, ?, ?)'
261
+ const cBlob = new Uint8Array([8, 6, 7, 5, 3, 0, 9])
262
+ const cDouble = Math.PI
263
+ const cInt = 42
264
+ const cNull = null
265
+ const cText = 'foobar'
270
266
 
271
267
  for await (const stmt of i(sqlite3.statements(db, sql))) {
272
- expect(await sqlite3.column_name(stmt, 0)).toEqual('column1');
273
- expect(await sqlite3.column_name(stmt, 1)).toEqual('column2');
274
- expect(await sqlite3.column_name(stmt, 2)).toEqual('column3');
275
- expect(await sqlite3.column_name(stmt, 3)).toEqual('column4');
276
- expect(await sqlite3.column_name(stmt, 4)).toEqual('column5');
277
-
278
- expect(await sqlite3.column_names(stmt))
279
- .toEqual(['column1', 'column2', 'column3', 'column4', 'column5']);
280
-
281
- rc = await sqlite3.bind_collection(stmt, [
282
- cBlob,
283
- cDouble,
284
- cInt,
285
- cNull,
286
- cText,
287
- ]);
288
- expect(rc).toEqual(SQLite.SQLITE_OK);
268
+ expect(await sqlite3.column_name(stmt, 0)).toEqual('column1')
269
+ expect(await sqlite3.column_name(stmt, 1)).toEqual('column2')
270
+ expect(await sqlite3.column_name(stmt, 2)).toEqual('column3')
271
+ expect(await sqlite3.column_name(stmt, 3)).toEqual('column4')
272
+ expect(await sqlite3.column_name(stmt, 4)).toEqual('column5')
273
+
274
+ expect(await sqlite3.column_names(stmt)).toEqual(['column1', 'column2', 'column3', 'column4', 'column5'])
275
+
276
+ rc = await sqlite3.bind_collection(stmt, [cBlob, cDouble, cInt, cNull, cText])
277
+ expect(rc).toEqual(SQLite.SQLITE_OK)
289
278
 
290
279
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
291
- expect(rc).toEqual(SQLite.SQLITE_ROW);
280
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
292
281
  expect(await sqlite3.data_count(stmt)).toEqual(5)
293
- expect(await sqlite3.column_count(stmt)).toEqual(5);
294
-
295
- const row = await sqlite3.row(stmt);
296
- expect(row.length).toEqual(5);
297
-
298
- expect(row[0] instanceof Uint8Array).toBeTrue();
299
- expect([...row[0]]).toEqual([...cBlob]);
300
- expect(row[1]).toEqual(cDouble);
301
- expect(row[2]).toEqual(cInt);
302
- expect(row[3]).toEqual(cNull);
303
- expect(row[4]).toEqual(cText);
304
- }
282
+ expect(await sqlite3.column_count(stmt)).toEqual(5)
283
+
284
+ const row = await sqlite3.row(stmt)
285
+ expect(row.length).toEqual(5)
286
+
287
+ expect(row[0] instanceof Uint8Array).toBeTrue()
288
+ expect([...row[0]]).toEqual([...cBlob])
289
+ expect(row[1]).toEqual(cDouble)
290
+ expect(row[2]).toEqual(cInt)
291
+ expect(row[3]).toEqual(cNull)
292
+ expect(row[4]).toEqual(cText)
293
+ }
305
294
  }
306
- });
295
+ })
307
296
 
308
- it('should bind collection object', async function() {
309
- let rc;
310
- const sql = 'VALUES (:cBlob, :cDouble, :cInt, :cNull, :cText)';
311
- const cBlob = new Uint8Array([8, 6, 7, 5, 3, 0, 9]);
312
- const cDouble = Math.PI;
313
- const cInt = 42;
314
- const cNull = null;
315
- const cText = 'foobar';
297
+ it('should bind collection object', async function () {
298
+ let rc
299
+ const sql = 'VALUES (:cBlob, :cDouble, :cInt, :cNull, :cText)'
300
+ const cBlob = new Uint8Array([8, 6, 7, 5, 3, 0, 9])
301
+ const cDouble = Math.PI
302
+ const cInt = 42
303
+ const cNull = null
304
+ const cText = 'foobar'
316
305
 
317
306
  for await (const stmt of i(sqlite3.statements(db, sql))) {
318
- expect(await sqlite3.bind_parameter_count(stmt)).toEqual(5);
319
- expect(await sqlite3.bind_parameter_name(stmt, 1)).toEqual(':cBlob');
320
- expect(await sqlite3.bind_parameter_name(stmt, 2)).toEqual(':cDouble');
321
- expect(await sqlite3.bind_parameter_name(stmt, 3)).toEqual(':cInt');
322
- expect(await sqlite3.bind_parameter_name(stmt, 4)).toEqual(':cNull');
323
- expect(await sqlite3.bind_parameter_name(stmt, 5)).toEqual(':cText');
307
+ expect(await sqlite3.bind_parameter_count(stmt)).toEqual(5)
308
+ expect(await sqlite3.bind_parameter_name(stmt, 1)).toEqual(':cBlob')
309
+ expect(await sqlite3.bind_parameter_name(stmt, 2)).toEqual(':cDouble')
310
+ expect(await sqlite3.bind_parameter_name(stmt, 3)).toEqual(':cInt')
311
+ expect(await sqlite3.bind_parameter_name(stmt, 4)).toEqual(':cNull')
312
+ expect(await sqlite3.bind_parameter_name(stmt, 5)).toEqual(':cText')
324
313
 
325
314
  rc = await sqlite3.bind_collection(stmt, {
326
315
  ':cBlob': cBlob,
327
316
  ':cDouble': cDouble,
328
317
  ':cInt': cInt,
329
318
  ':cNull': cNull,
330
- ':cText': cText
331
- });
332
- expect(rc).toEqual(SQLite.SQLITE_OK);
319
+ ':cText': cText,
320
+ })
321
+ expect(rc).toEqual(SQLite.SQLITE_OK)
333
322
 
334
323
  while ((rc = await sqlite3.step(stmt)) !== SQLite.SQLITE_DONE) {
335
- expect(rc).toEqual(SQLite.SQLITE_ROW);
336
-
337
- expect(await sqlite3.column_count(stmt)).toEqual(5);
338
- const row = await sqlite3.row(stmt);
339
- expect(row.length).toEqual(5);
340
-
341
- expect(row[0] instanceof Uint8Array).toBeTrue();
342
- expect([...row[0]]).toEqual([...cBlob]);
343
- expect(row[1]).toEqual(cDouble);
344
- expect(row[2]).toEqual(cInt);
345
- expect(row[3]).toEqual(cNull);
346
- expect(row[4]).toEqual(cText);
347
- }
324
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
325
+
326
+ expect(await sqlite3.column_count(stmt)).toEqual(5)
327
+ const row = await sqlite3.row(stmt)
328
+ expect(row.length).toEqual(5)
329
+
330
+ expect(row[0] instanceof Uint8Array).toBeTrue()
331
+ expect([...row[0]]).toEqual([...cBlob])
332
+ expect(row[1]).toEqual(cDouble)
333
+ expect(row[2]).toEqual(cInt)
334
+ expect(row[3]).toEqual(cNull)
335
+ expect(row[4]).toEqual(cText)
336
+ }
348
337
  }
349
- });
338
+ })
350
339
 
351
- it('should allow unscoped lifetime', async function() {
352
- let rc;
340
+ it('should allow unscoped lifetime', async function () {
341
+ let rc
353
342
 
354
- rc = await sqlite3.exec(db, `
343
+ rc = await sqlite3.exec(
344
+ db,
345
+ `
355
346
  CREATE TABLE t AS VALUES ('foo', 0), ('bar', 1), ('baz', 2);
356
- `);
357
- expect(rc).toEqual(SQLite.SQLITE_OK);
347
+ `,
348
+ )
349
+ expect(rc).toEqual(SQLite.SQLITE_OK)
358
350
 
359
- let stmt;
360
- const sql = 'SELECT column2 FROM t WHERE column1 = ?';
351
+ let stmt
352
+ const sql = 'SELECT column2 FROM t WHERE column1 = ?'
361
353
  for await (const s of i(sqlite3.statements(db, sql, { unscoped: true }))) {
362
354
  if (s) {
363
- stmt = s;
355
+ stmt = s
364
356
  }
365
357
  }
366
- expect(stmt).toBeGreaterThan(0);
358
+ expect(stmt).toBeGreaterThan(0)
367
359
 
368
360
  // The statement should be active beyond the iterator lifecycle.
369
- rc = await sqlite3.bind_text(stmt, 1, 'foo');
370
- expect(rc).toEqual(SQLite.SQLITE_OK);
371
- rc = await sqlite3.step(stmt);
372
- expect(rc).toEqual(SQLite.SQLITE_ROW);
373
- await expectAsync(sqlite3.column_int(stmt, 0)).toBeResolvedTo(0);
374
-
375
- rc = await sqlite3.reset(stmt);
376
- expect(rc).toEqual(SQLite.SQLITE_OK);
377
-
378
- rc = await sqlite3.bind_text(stmt, 1, 'bar');
379
- expect(rc).toEqual(SQLite.SQLITE_OK);
380
- rc = await sqlite3.step(stmt);
381
- expect(rc).toEqual(SQLite.SQLITE_ROW);
382
- await expectAsync(sqlite3.column_int(stmt, 0)).toBeResolvedTo(1);
383
-
384
- rc = await sqlite3.step(stmt);
385
- expect(rc).toEqual(SQLite.SQLITE_DONE);
386
-
387
- rc = await sqlite3.finalize(stmt);
388
- expect(rc).toEqual(SQLite.SQLITE_OK);
389
- });
390
-
391
- it('should clear bindings', async function() {
392
- let rc;
393
-
394
- const sql = 'SELECT ?';
361
+ rc = await sqlite3.bind_text(stmt, 1, 'foo')
362
+ expect(rc).toEqual(SQLite.SQLITE_OK)
363
+ rc = await sqlite3.step(stmt)
364
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
365
+ await expectAsync(sqlite3.column_int(stmt, 0)).toBeResolvedTo(0)
366
+
367
+ rc = await sqlite3.reset(stmt)
368
+ expect(rc).toEqual(SQLite.SQLITE_OK)
369
+
370
+ rc = await sqlite3.bind_text(stmt, 1, 'bar')
371
+ expect(rc).toEqual(SQLite.SQLITE_OK)
372
+ rc = await sqlite3.step(stmt)
373
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
374
+ await expectAsync(sqlite3.column_int(stmt, 0)).toBeResolvedTo(1)
375
+
376
+ rc = await sqlite3.step(stmt)
377
+ expect(rc).toEqual(SQLite.SQLITE_DONE)
378
+
379
+ rc = await sqlite3.finalize(stmt)
380
+ expect(rc).toEqual(SQLite.SQLITE_OK)
381
+ })
382
+
383
+ it('should clear bindings', async function () {
384
+ let rc
385
+
386
+ const sql = 'SELECT ?'
395
387
  for await (const stmt of i(sqlite3.statements(db, sql))) {
396
388
  {
397
- rc = await sqlite3.bind_int(stmt, 1, 42);
398
- expect(rc).toEqual(SQLite.SQLITE_OK);
389
+ rc = await sqlite3.bind_int(stmt, 1, 42)
390
+ expect(rc).toEqual(SQLite.SQLITE_OK)
399
391
 
400
- rc = await sqlite3.reset(stmt);
401
- expect(rc).toEqual(SQLite.SQLITE_OK);
392
+ rc = await sqlite3.reset(stmt)
393
+ expect(rc).toEqual(SQLite.SQLITE_OK)
402
394
 
403
- rc = await sqlite3.step(stmt);
404
- expect(rc).toEqual(SQLite.SQLITE_ROW);
395
+ rc = await sqlite3.step(stmt)
396
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
405
397
 
406
- const value = await sqlite3.column(stmt, 0);
407
- expect(value).toEqual(42);
398
+ const value = await sqlite3.column(stmt, 0)
399
+ expect(value).toEqual(42)
408
400
  }
409
401
 
410
402
  {
411
- rc = await sqlite3.clear_bindings(stmt);
412
- expect(rc).toEqual(SQLite.SQLITE_OK);
403
+ rc = await sqlite3.clear_bindings(stmt)
404
+ expect(rc).toEqual(SQLite.SQLITE_OK)
405
+
406
+ rc = await sqlite3.reset(stmt)
407
+ expect(rc).toEqual(SQLite.SQLITE_OK)
413
408
 
414
- rc = await sqlite3.reset(stmt);
415
- expect(rc).toEqual(SQLite.SQLITE_OK);
416
-
417
- rc = await sqlite3.step(stmt);
418
- expect(rc).toEqual(SQLite.SQLITE_ROW);
409
+ rc = await sqlite3.step(stmt)
410
+ expect(rc).toEqual(SQLite.SQLITE_ROW)
419
411
 
420
- const value = await sqlite3.column(stmt, 0);
421
- expect(value).not.toEqual(42);
412
+ const value = await sqlite3.column(stmt, 0)
413
+ expect(value).not.toEqual(42)
422
414
  }
423
415
  }
424
- });
425
- });
416
+ })
417
+ })
426
418
  }
427
419
 
428
420
  // sqlite3.statements() returns an async iterator, but its Comlink
429
421
  // proxy needs this wrapper to be used.
430
422
  async function* i(p) {
431
- const x = await p;
423
+ const x = await p
432
424
  try {
433
- let value, done;
425
+ let value, done
434
426
  while (true) {
435
- ({ value, done } = await x.next());
427
+ ;({ value, done } = await x.next())
436
428
  if (!done) {
437
- yield value;
429
+ yield value
438
430
  } else {
439
- break;
431
+ break
440
432
  }
441
433
  }
442
434
  } catch (e) {
443
- await x.throw(e);
435
+ await x.throw(e)
444
436
  } finally {
445
- await x.return();
437
+ await x.return()
446
438
  }
447
- }
439
+ }