better-sqlite3-multiple-ciphers 7.4.7-beta.0 → 7.5.1-beta.0

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 (81) hide show
  1. package/README.md +8 -6
  2. package/deps/download.sh +111 -108
  3. package/deps/setup.ps1 +10 -12
  4. package/deps/sqlite3/sqlite3.c +272560 -0
  5. package/deps/sqlite3/sqlite3.h +12770 -0
  6. package/deps/sqlite3/sqlite3ext.h +675 -0
  7. package/deps/sqlite3.gyp +17 -7
  8. package/deps/symlink.js +7 -4
  9. package/lib/database.js +17 -6
  10. package/lib/sqlite-error.js +1 -2
  11. package/package.json +11 -5
  12. package/src/better_sqlite3.cpp +46 -35
  13. package/src/better_sqlite3.hpp +40 -38
  14. package/.gitattributes +0 -1
  15. package/.github/workflows/prebuild.yml +0 -49
  16. package/.github/workflows/test.yml +0 -59
  17. package/benchmark/benchmark.js +0 -31
  18. package/benchmark/drivers.js +0 -21
  19. package/benchmark/index.js +0 -83
  20. package/benchmark/seed.js +0 -47
  21. package/benchmark/trials.js +0 -65
  22. package/benchmark/types/insert.js +0 -16
  23. package/benchmark/types/select-all.js +0 -14
  24. package/benchmark/types/select-iterate.js +0 -23
  25. package/benchmark/types/select.js +0 -14
  26. package/benchmark/types/transaction.js +0 -40
  27. package/deps/extract.js +0 -16
  28. package/deps/sqlite3.tar.gz +0 -0
  29. package/docs/api.md +0 -645
  30. package/docs/benchmark.md +0 -38
  31. package/docs/compilation.md +0 -76
  32. package/docs/integer.md +0 -79
  33. package/docs/performance.md +0 -39
  34. package/docs/threads.md +0 -97
  35. package/docs/tips.md +0 -35
  36. package/docs/troubleshooting.md +0 -23
  37. package/docs/unsafe.md +0 -16
  38. package/src/better_sqlite3.lzz +0 -88
  39. package/src/objects/backup.lzz +0 -138
  40. package/src/objects/database.lzz +0 -468
  41. package/src/objects/statement-iterator.lzz +0 -138
  42. package/src/objects/statement.lzz +0 -323
  43. package/src/util/bind-map.lzz +0 -73
  44. package/src/util/binder.lzz +0 -190
  45. package/src/util/constants.lzz +0 -151
  46. package/src/util/custom-aggregate.lzz +0 -121
  47. package/src/util/custom-function.lzz +0 -59
  48. package/src/util/custom-table.lzz +0 -397
  49. package/src/util/data-converter.lzz +0 -17
  50. package/src/util/data.lzz +0 -145
  51. package/src/util/macros.lzz +0 -159
  52. package/src/util/query-macros.lzz +0 -71
  53. package/test/00.setup.js +0 -25
  54. package/test/01.sqlite-error.js +0 -27
  55. package/test/10.database.open.js +0 -159
  56. package/test/11.database.close.js +0 -68
  57. package/test/12.database.pragma.js +0 -65
  58. package/test/13.database.prepare.js +0 -60
  59. package/test/14.database.exec.js +0 -46
  60. package/test/20.statement.run.js +0 -170
  61. package/test/21.statement.get.js +0 -109
  62. package/test/22.statement.all.js +0 -129
  63. package/test/23.statement.iterate.js +0 -223
  64. package/test/24.statement.bind.js +0 -107
  65. package/test/25.statement.columns.js +0 -46
  66. package/test/30.database.transaction.js +0 -157
  67. package/test/31.database.checkpoint.js +0 -62
  68. package/test/32.database.function.js +0 -211
  69. package/test/33.database.aggregate.js +0 -603
  70. package/test/34.database.table.js +0 -671
  71. package/test/35.database.load-extension.js +0 -75
  72. package/test/36.database.backup.js +0 -240
  73. package/test/37.database.serialize.js +0 -81
  74. package/test/40.bigints.js +0 -145
  75. package/test/41.at-exit.js +0 -52
  76. package/test/42.integrity.js +0 -531
  77. package/test/43.verbose.js +0 -100
  78. package/test/44.worker-threads.js +0 -66
  79. package/test/45.unsafe-mode.js +0 -52
  80. package/test/46.encryption.js +0 -69
  81. package/test/50.misc.js +0 -44
@@ -1,531 +0,0 @@
1
- 'use strict';
2
- const fs = require('fs');
3
- const path = require('path');
4
- const Database = require('../.');
5
-
6
- describe('integrity checks', function () {
7
- beforeEach(function () {
8
- let func = () => {};
9
- this.useFunc = fn => { func = fn; };
10
- this.db = new Database(util.next());
11
- this.db.prepare("CREATE TABLE entries (a TEXT, b INTEGER, c REAL, d BLOB, e TEXT)").run();
12
- this.db.prepare("INSERT INTO entries WITH RECURSIVE temp(a, b, c, d, e) AS (SELECT 'foo', 1, 3.14, x'dddddddd', NULL UNION ALL SELECT a, b + 1, c, d, e FROM temp LIMIT 5) SELECT * FROM temp").run();
13
- this.db.function('func', x => (func(), x));
14
- this.iterator = this.db.prepare("SELECT func(b) from entries ORDER BY rowid");
15
- this.reader = this.db.prepare("SELECT func(b) from entries ORDER BY rowid");
16
- this.writer = this.db.prepare("UPDATE entries SET c = c + 2.718")
17
- });
18
- afterEach(function () {
19
- this.db.close();
20
- });
21
-
22
- const allowed = fn => () => expect(fn).to.not.throw();
23
- const blocked = fn => () => expect(fn).to.throw(TypeError);
24
- const normally = fn => fn();
25
- const whileIterating = (self, fn) => {
26
- let count = 0;
27
- for (const _ of self.iterator.iterate()) { count += 1; fn(); }
28
- expect(count).to.equal(5);
29
- };
30
- const whileBusy = (self, fn) => {
31
- let count = 0;
32
- self.useFunc(() => { count += 1; fn(); });
33
- self.iterator.all();
34
- expect(count).to.equal(5);
35
- };
36
- const whileClosed = (self, fn) => {
37
- self.db.close();
38
- fn();
39
- };
40
-
41
- describe('Database#prepare()', function () {
42
- specify('while iterating (allowed)', function () {
43
- whileIterating(this, allowed(() => this.db.prepare('SELECT 555')));
44
- whileIterating(this, allowed(() => this.db.prepare('DELETE FROM entries')));
45
- normally(allowed(() => this.db.prepare('SELECT 555')));
46
- normally(allowed(() => this.db.prepare('DELETE FROM entries')));
47
- });
48
- specify('while busy (blocked)', function () {
49
- whileBusy(this, blocked(() => this.db.prepare('SELECT 555')));
50
- whileBusy(this, blocked(() => this.db.prepare('DELETE FROM entries')));
51
- normally(allowed(() => this.db.prepare('SELECT 555')));
52
- normally(allowed(() => this.db.prepare('DELETE FROM entries')));
53
- });
54
- specify('while closed (blocked)', function () {
55
- whileClosed(this, blocked(() => this.db.prepare('SELECT 555')));
56
- whileClosed(this, blocked(() => this.db.prepare('DELETE FROM entries')));
57
- });
58
- });
59
-
60
- describe('Database#exec()', function () {
61
- specify('while iterating (blocked)', function () {
62
- whileIterating(this, blocked(() => this.db.exec('SELECT 555')));
63
- whileIterating(this, blocked(() => this.db.exec('DELETE FROM entries')));
64
- normally(allowed(() => this.db.exec('SELECT 555')));
65
- normally(allowed(() => this.db.exec('DELETE FROM entries')));
66
- });
67
- specify('while busy (blocked)', function () {
68
- whileBusy(this, blocked(() => this.db.exec('SELECT 555')));
69
- whileBusy(this, blocked(() => this.db.exec('DELETE FROM entries')));
70
- normally(allowed(() => this.db.exec('SELECT 555')));
71
- normally(allowed(() => this.db.exec('DELETE FROM entries')));
72
- });
73
- specify('while closed (blocked)', function () {
74
- whileClosed(this, blocked(() => this.db.exec('SELECT 555')));
75
- whileClosed(this, blocked(() => this.db.exec('DELETE FROM entries')));
76
- });
77
- });
78
-
79
- describe('Database#pragma()', function () {
80
- specify('while iterating (blocked)', function () {
81
- whileIterating(this, blocked(() => this.db.pragma('cache_size')));
82
- normally(allowed(() => this.db.pragma('cache_size')));
83
- });
84
- specify('while busy (blocked)', function () {
85
- whileBusy(this, blocked(() => this.db.pragma('cache_size')));
86
- normally(allowed(() => this.db.pragma('cache_size')));
87
- });
88
- specify('while closed (blocked)', function () {
89
- whileClosed(this, blocked(() => this.db.pragma('cache_size')));
90
- });
91
- });
92
-
93
- describe('Database#pragma(\'wal_checkpoint(RESTART)\')', function () {
94
- specify('while iterating (blocked)', function () {
95
- whileIterating(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));
96
- normally(allowed(() => this.db.pragma('wal_checkpoint(RESTART)')));
97
- });
98
- specify('while busy (blocked)', function () {
99
- whileBusy(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));
100
- normally(allowed(() => this.db.pragma('wal_checkpoint(RESTART)')));
101
- });
102
- specify('while closed (blocked)', function () {
103
- whileClosed(this, blocked(() => this.db.pragma('wal_checkpoint(RESTART)')));
104
- });
105
- });
106
-
107
- describe('Database#backup()', function () {
108
- specify('while iterating (allowed)', async function () {
109
- const promises = [];
110
- whileIterating(this, allowed(() => promises.push(this.db.backup(util.next()))));
111
- expect(promises.length).to.equal(5);
112
- return Promise.all(promises);
113
- });
114
- specify('while busy (allowed)', async function () {
115
- const promises = [];
116
- whileBusy(this, allowed(() => promises.push(this.db.backup(util.next()))));
117
- expect(promises.length).to.equal(5);
118
- return Promise.all(promises);
119
- });
120
- specify('while closed (blocked)', async function () {
121
- const promises = [];
122
- whileClosed(this, allowed(() => promises.push(this.db.backup(util.next()))));
123
- expect(promises.length).to.equal(1);
124
- return Promise.all(promises.map(p =>
125
- p.then(() => { throw new Error('Promise should have been rejected'); }, () => {})
126
- ));
127
- });
128
- });
129
-
130
- describe('Database#function()', function () {
131
- specify('while iterating (blocked)', function () {
132
- let i = 0;
133
- whileIterating(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));
134
- expect(i).to.equal(5);
135
- normally(allowed(() => this.db.function(`fn_${++i}`, () => {})));
136
- });
137
- specify('while busy (blocked)', function () {
138
- let i = 0;
139
- whileBusy(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));
140
- expect(i).to.equal(5);
141
- normally(allowed(() => this.db.function(`fn_${++i}`, () => {})));
142
- });
143
- specify('while closed (blocked)', function () {
144
- let i = 0;
145
- whileClosed(this, blocked(() => this.db.function(`fn_${++i}`, () => {})));
146
- expect(i).to.equal(1);
147
- });
148
- });
149
-
150
- describe('Database#aggregate()', function () {
151
- specify('while iterating (blocked)', function () {
152
- let i = 0;
153
- whileIterating(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));
154
- expect(i).to.equal(5);
155
- normally(allowed(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));
156
- });
157
- specify('while busy (blocked)', function () {
158
- let i = 0;
159
- whileBusy(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));
160
- expect(i).to.equal(5);
161
- normally(allowed(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));
162
- });
163
- specify('while closed (blocked)', function () {
164
- let i = 0;
165
- whileClosed(this, blocked(() => this.db.aggregate(`agg_${++i}`, { step: () => {} })));
166
- expect(i).to.equal(1);
167
- });
168
- });
169
-
170
- describe('Database#table()', function () {
171
- specify('while iterating (blocked)', function () {
172
- let i = 0;
173
- whileIterating(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));
174
- expect(i).to.equal(5);
175
- normally(allowed(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));
176
- });
177
- specify('while busy (blocked)', function () {
178
- let i = 0;
179
- whileBusy(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));
180
- expect(i).to.equal(5);
181
- normally(allowed(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));
182
- });
183
- specify('while closed (blocked)', function () {
184
- let i = 0;
185
- whileClosed(this, blocked(() => this.db.table(`tbl_${++i}`, { columns: ['x'], *rows() {} })));
186
- expect(i).to.equal(1);
187
- });
188
- });
189
-
190
- describe('Database#loadExtension()', function () {
191
- let filepath;
192
- before(function () {
193
- const releaseFilepath = path.join(__dirname, '..', 'build', 'Release', 'test_extension.node');
194
- const debugFilepath = path.join(__dirname, '..', 'build', 'Debug', 'test_extension.node');
195
- try {
196
- fs.accessSync(releaseFilepath);
197
- filepath = releaseFilepath;
198
- } catch (_) {
199
- fs.accessSync(debugFilepath);
200
- filepath = debugFilepath;
201
- }
202
- });
203
-
204
- specify('while iterating (blocked)', function () {
205
- whileIterating(this, blocked(() => this.db.loadExtension(filepath)));
206
- normally(allowed(() => this.db.loadExtension(filepath)));
207
- });
208
- specify('while busy (blocked)', function () {
209
- whileBusy(this, blocked(() => this.db.loadExtension(filepath)));
210
- normally(allowed(() => this.db.loadExtension(filepath)));
211
- });
212
- specify('while closed (blocked)', function () {
213
- whileClosed(this, blocked(() => this.db.loadExtension(filepath)));
214
- });
215
- });
216
-
217
- describe('Database#close()', function () {
218
- specify('while iterating (blocked)', function () {
219
- whileIterating(this, blocked(() => this.db.close()));
220
- normally(allowed(() => this.db.close()));
221
- });
222
- specify('while busy (blocked)', function () {
223
- whileBusy(this, blocked(() => this.db.close()));
224
- normally(allowed(() => this.db.close()));
225
- });
226
- specify('while closed (allowed)', function () {
227
- whileClosed(this, allowed(() => this.db.close()));
228
- });
229
- });
230
-
231
- describe('Database#defaultSafeIntegers()', function () {
232
- specify('while iterating (allowed)', function () {
233
- let bool = true;
234
- whileIterating(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));
235
- });
236
- specify('while busy (allowed)', function () {
237
- let bool = true;
238
- whileBusy(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));
239
- });
240
- specify('while closed (allowed)', function () {
241
- let bool = true;
242
- whileClosed(this, allowed(() => this.db.defaultSafeIntegers(bool = !bool)));
243
- });
244
- });
245
-
246
- describe('Database#open', function () {
247
- specify('while iterating (allowed)', function () {
248
- whileIterating(this, allowed(() => expect(this.db.open).to.be.true));
249
- });
250
- specify('while busy (allowed)', function () {
251
- whileBusy(this, allowed(() => expect(this.db.open).to.be.true));
252
- });
253
- specify('while closed (allowed)', function () {
254
- whileClosed(this, allowed(() => expect(this.db.open).to.be.false));
255
- });
256
- });
257
-
258
- describe('Database#inTransaction', function () {
259
- specify('while iterating (allowed)', function () {
260
- this.db.exec('BEGIN');
261
- whileIterating(this, allowed(() => expect(this.db.inTransaction).to.be.true));
262
- });
263
- specify('while busy (allowed)', function () {
264
- this.db.exec('BEGIN');
265
- whileBusy(this, allowed(() => expect(this.db.inTransaction).to.be.true));
266
- });
267
- specify('while closed (allowed)', function () {
268
- this.db.exec('BEGIN');
269
- whileClosed(this, allowed(() => expect(this.db.inTransaction).to.be.false));
270
- });
271
- });
272
-
273
- describe('Statement#run()', function () {
274
- specify('while iterating (blocked)', function () {
275
- whileIterating(this, blocked(() => this.writer.run()));
276
- normally(allowed(() => this.writer.run()));
277
- });
278
- specify('while busy (blocked)', function () {
279
- whileBusy(this, blocked(() => this.writer.run()));
280
- normally(allowed(() => this.writer.run()));
281
- });
282
- specify('while closed (blocked)', function () {
283
- whileClosed(this, blocked(() => this.writer.run()));
284
- });
285
- });
286
-
287
- describe('Statement#get()', function () {
288
- specify('while iterating (allowed)', function () {
289
- whileIterating(this, allowed(() => this.reader.get()));
290
- normally(allowed(() => this.reader.get()));
291
- });
292
- specify('while self-iterating (blocked)', function () {
293
- whileIterating(this, blocked(() => this.iterator.get()));
294
- normally(allowed(() => this.iterator.get()));
295
- });
296
- specify('while busy (blocked)', function () {
297
- whileBusy(this, blocked(() => this.reader.get()));
298
- normally(allowed(() => this.reader.get()));
299
- });
300
- specify('while closed (blocked)', function () {
301
- whileClosed(this, blocked(() => this.reader.get()));
302
- });
303
- });
304
-
305
- describe('Statement#all()', function () {
306
- specify('while iterating (allowed)', function () {
307
- whileIterating(this, allowed(() => this.reader.all()));
308
- normally(allowed(() => this.reader.all()));
309
- });
310
- specify('while self-iterating (blocked)', function () {
311
- whileIterating(this, blocked(() => this.iterator.all()));
312
- normally(allowed(() => this.iterator.all()));
313
- });
314
- specify('while busy (blocked)', function () {
315
- whileBusy(this, blocked(() => this.reader.all()));
316
- normally(allowed(() => this.reader.all()));
317
- });
318
- specify('while closed (blocked)', function () {
319
- whileClosed(this, blocked(() => this.reader.all()));
320
- });
321
- });
322
-
323
- describe('Statement#iterate()', function () {
324
- specify('while iterating (allowed)', function () {
325
- whileIterating(this, allowed(() => Array.from(this.reader.iterate())));
326
- normally(allowed(() => Array.from(this.reader.iterate())));
327
- });
328
- specify('while self-iterating (blocked)', function () {
329
- whileIterating(this, blocked(() => Array.from(this.iterator.iterate())));
330
- normally(allowed(() => Array.from(this.iterator.iterate())));
331
- });
332
- specify('while busy (blocked)', function () {
333
- whileBusy(this, blocked(() => Array.from(this.reader.iterate())));
334
- normally(allowed(() => Array.from(this.reader.iterate())));
335
- });
336
- specify('while closed (blocked)', function () {
337
- whileClosed(this, blocked(() => Array.from(this.reader.iterate())));
338
- });
339
- });
340
-
341
- describe('Statement#bind()', function () {
342
- const bind = (stmt) => {
343
- if (!stmt.__bound) {
344
- stmt.bind();
345
- stmt.__bound = true;
346
- }
347
- };
348
- specify('while iterating (allowed)', function () {
349
- whileIterating(this, allowed(() => bind(this.reader)));
350
- });
351
- specify('while self-iterating (blocked)', function () {
352
- whileIterating(this, blocked(() => bind(this.iterator)));
353
- normally(allowed(() => bind(this.iterator)));
354
- });
355
- specify('while busy (blocked)', function () {
356
- whileBusy(this, blocked(() => bind(this.reader)));
357
- normally(allowed(() => bind(this.reader)));
358
- });
359
- specify('while closed (blocked)', function () {
360
- whileClosed(this, blocked(() => bind(this.reader)));
361
- });
362
- });
363
-
364
- describe('Statement#pluck()', function () {
365
- specify('while iterating (allowed)', function () {
366
- whileIterating(this, allowed(() => this.reader.pluck()));
367
- normally(allowed(() => this.reader.pluck()));
368
- });
369
- specify('while self-iterating (blocked)', function () {
370
- whileIterating(this, blocked(() => this.iterator.pluck()));
371
- normally(allowed(() => this.iterator.pluck()));
372
- });
373
- specify('while busy (blocked)', function () {
374
- whileBusy(this, blocked(() => this.reader.pluck()));
375
- normally(allowed(() => this.reader.pluck()));
376
- });
377
- specify('while closed (allowed)', function () {
378
- whileClosed(this, allowed(() => this.reader.pluck()));
379
- });
380
- });
381
-
382
- describe('Statement#expand()', function () {
383
- specify('while iterating (allowed)', function () {
384
- whileIterating(this, allowed(() => this.reader.expand()));
385
- normally(allowed(() => this.reader.expand()));
386
- });
387
- specify('while self-iterating (blocked)', function () {
388
- whileIterating(this, blocked(() => this.iterator.expand()));
389
- normally(allowed(() => this.iterator.expand()));
390
- });
391
- specify('while busy (blocked)', function () {
392
- whileBusy(this, blocked(() => this.reader.expand()));
393
- normally(allowed(() => this.reader.expand()));
394
- });
395
- specify('while closed (allowed)', function () {
396
- whileClosed(this, allowed(() => this.reader.expand()));
397
- });
398
- });
399
-
400
- describe('Statement#raw()', function () {
401
- specify('while iterating (allowed)', function () {
402
- whileIterating(this, allowed(() => this.reader.raw()));
403
- normally(allowed(() => this.reader.raw()));
404
- });
405
- specify('while self-iterating (blocked)', function () {
406
- whileIterating(this, blocked(() => this.iterator.raw()));
407
- normally(allowed(() => this.iterator.raw()));
408
- });
409
- specify('while busy (blocked)', function () {
410
- whileBusy(this, blocked(() => this.reader.raw()));
411
- normally(allowed(() => this.reader.raw()));
412
- });
413
- specify('while closed (allowed)', function () {
414
- whileClosed(this, allowed(() => this.reader.raw()));
415
- });
416
- });
417
-
418
- describe('Statement#safeIntegers()', function () {
419
- specify('while iterating (allowed)', function () {
420
- whileIterating(this, allowed(() => this.reader.safeIntegers()));
421
- normally(allowed(() => this.reader.safeIntegers()));
422
- });
423
- specify('while self-iterating (blocked)', function () {
424
- whileIterating(this, blocked(() => this.iterator.safeIntegers()));
425
- normally(allowed(() => this.iterator.safeIntegers()));
426
- });
427
- specify('while busy (blocked)', function () {
428
- whileBusy(this, blocked(() => this.reader.safeIntegers()));
429
- normally(allowed(() => this.reader.safeIntegers()));
430
- });
431
- specify('while closed (allowed)', function () {
432
- whileClosed(this, allowed(() => this.reader.safeIntegers()));
433
- });
434
- });
435
-
436
- describe('Statement#columns()', function () {
437
- specify('while iterating (allowed)', function () {
438
- whileIterating(this, allowed(() => this.reader.columns()));
439
- normally(allowed(() => this.reader.columns()));
440
- });
441
- specify('while self-iterating (allowed)', function () {
442
- whileIterating(this, allowed(() => this.iterator.columns()));
443
- normally(allowed(() => this.iterator.columns()));
444
- });
445
- specify('while busy (blocked)', function () {
446
- whileBusy(this, blocked(() => this.reader.columns()));
447
- normally(allowed(() => this.reader.columns()));
448
- });
449
- specify('while closed (blocked)', function () {
450
- whileClosed(this, blocked(() => this.reader.columns()));
451
- });
452
- });
453
-
454
- describe('StatementIterator#next()', function () {
455
- specify('while iterating (allowed)', function () {
456
- const iterator = this.reader.iterate();
457
- try {
458
- whileIterating(this, allowed(() => iterator.next()));
459
- normally(allowed(() => iterator.next()));
460
- } finally {
461
- iterator.return();
462
- }
463
- });
464
- specify('while self-iterating (allowed)', function () {
465
- const iterator = this.iterator.iterate();
466
- try {
467
- let count = 0;
468
- for (const _ of iterator) {
469
- count += 1;
470
- iterator.next();
471
- }
472
- expect(count).to.equal(3);
473
- } finally {
474
- iterator.return();
475
- }
476
- });
477
- specify('while busy (blocked)', function () {
478
- const iterator = this.reader.iterate();
479
- try {
480
- whileBusy(this, blocked(() => iterator.next()));
481
- normally(allowed(() => iterator.next()));
482
- } finally {
483
- iterator.return();
484
- }
485
- });
486
- specify('while closed (allowed)', function () {
487
- const iterator = this.reader.iterate();
488
- iterator.return();
489
- whileClosed(this, allowed(() => iterator.next()));
490
- });
491
- });
492
-
493
- describe('StatementIterator#return()', function () {
494
- specify('while iterating (allowed)', function () {
495
- const iterator = this.reader.iterate();
496
- try {
497
- whileIterating(this, allowed(() => iterator.return()));
498
- normally(allowed(() => iterator.return()));
499
- } finally {
500
- iterator.return();
501
- }
502
- });
503
- specify('while self-iterating (allowed)', function () {
504
- const iterator = this.iterator.iterate();
505
- try {
506
- let count = 0;
507
- for (const _ of iterator) {
508
- count += 1;
509
- iterator.return();
510
- }
511
- expect(count).to.equal(1);
512
- } finally {
513
- iterator.return();
514
- }
515
- });
516
- specify('while busy (blocked)', function () {
517
- const iterator = this.reader.iterate();
518
- try {
519
- whileBusy(this, blocked(() => iterator.return()));
520
- normally(allowed(() => iterator.return()));
521
- } finally {
522
- iterator.return();
523
- }
524
- });
525
- specify('while closed (allowed)', function () {
526
- const iterator = this.reader.iterate();
527
- iterator.return();
528
- whileClosed(this, allowed(() => iterator.return()));
529
- });
530
- });
531
- });
@@ -1,100 +0,0 @@
1
- 'use strict';
2
- const Database = require('../.');
3
-
4
- describe('verbose mode', function () {
5
- afterEach(function () {
6
- if (this.db) this.db.close();
7
- });
8
-
9
- it('should throw when not given a function or null/undefined', function () {
10
- expect(() => (this.db = new Database(util.next(), { verbose: false }))).to.throw(TypeError);
11
- expect(() => (this.db = new Database(util.next(), { verbose: true }))).to.throw(TypeError);
12
- expect(() => (this.db = new Database(util.next(), { verbose: 123 }))).to.throw(TypeError);
13
- expect(() => (this.db = new Database(util.next(), { verbose: 'null' }))).to.throw(TypeError);
14
- expect(() => (this.db = new Database(util.next(), { verbose: {} }))).to.throw(TypeError);
15
- expect(() => (this.db = new Database(util.next(), { verbose: [] }))).to.throw(TypeError);
16
- });
17
- it('should allow explicit null or undefined as a no-op', function () {
18
- for (const verbose of [undefined, null]) {
19
- const db = this.db = new Database(util.next(), { verbose });
20
- db.exec('select 5');
21
- db.close();
22
- }
23
- });
24
- it('should invoke the given function with all executed SQL', function () {
25
- let calls = [];
26
- function verbose(...args) {
27
- calls.push([this, ...args]);
28
- }
29
- const db = this.db = new Database(util.next(), { verbose });
30
- const stmt = db.prepare('select ?');
31
- db.exec('select 5');
32
- db.prepare('create table data (x)').run();
33
- stmt.get(BigInt(10));
34
- stmt.all(BigInt(15));
35
- stmt.iterate(BigInt(20)).return();
36
- for (const x of stmt.iterate(BigInt(25))) {}
37
- db.pragma('cache_size');
38
- db.prepare("insert into data values ('hi')").run();
39
- db.prepare("insert into data values ('bye')").run();
40
- expect(Array.from(db.prepare('select x from data order by rowid').pluck().iterate()))
41
- .to.deep.equal(['hi', 'bye']);
42
- expect(calls).to.deep.equal([
43
- [undefined, 'select 5'],
44
- [undefined, 'create table data (x)'],
45
- [undefined, 'select 10'],
46
- [undefined, 'select 15'],
47
- [undefined, 'select 25'],
48
- [undefined, 'PRAGMA cache_size'],
49
- [undefined, "insert into data values ('hi')"],
50
- [undefined, "insert into data values ('bye')"],
51
- [undefined, 'select x from data order by rowid'],
52
- ]);
53
- });
54
- it('should not fully expand very long bound parameter', function () {
55
- let calls = [];
56
- function verbose(...args) {
57
- calls.push([this, ...args]);
58
- }
59
- const db = this.db = new Database(util.next(), { verbose });
60
- const stmt = db.prepare('select ?');
61
- stmt.get('this is a fairly short parameter');
62
- stmt.get('this is a slightly longer parameter');
63
- stmt.get('this is surely a very long bound parameter value that doesnt need to be logged in its entirety');
64
- expect(calls).to.deep.equal([
65
- [undefined, "select 'this is a fairly short parameter'"],
66
- [undefined, "select 'this is a slightly longer parame'/*+3 bytes*/"],
67
- [undefined, "select 'this is surely a very long bound'/*+62 bytes*/"],
68
- ]);
69
- });
70
- it('should abort the execution if the logger function throws', function () {
71
- let fail = false;
72
- let failures = 0;
73
- const err = new Error('foo');
74
- const db = this.db = new Database(util.next(), { verbose: () => { if (fail) throw err; } });
75
- db.prepare('create table data (x)').run();
76
- db.function('fn', (value) => {
77
- if (fail) failures += 1;
78
- return value;
79
- });
80
- const shouldThrow = (fn) => {
81
- expect(fn).to.not.throw();
82
- expect(fn).to.not.throw();
83
- fail = true;
84
- try {
85
- expect(fn).to.throw(err);
86
- } finally {
87
- fail = false;
88
- }
89
- expect(fn).to.not.throw();
90
- expect(failures).to.equal(0);
91
- };
92
- const use = (stmt, fn) => () => fn(stmt);
93
- shouldThrow(() => db.exec('select fn(5)'));
94
- shouldThrow(use(db.prepare('insert into data values (fn(5))'), stmt => stmt.run()));
95
- shouldThrow(use(db.prepare('insert into data values (fn(?))'), stmt => stmt.run(5)));
96
- shouldThrow(use(db.prepare('select fn(?)'), stmt => stmt.get(5)));
97
- shouldThrow(use(db.prepare('select fn(?)'), stmt => stmt.all(5)));
98
- shouldThrow(use(db.prepare('select fn(?)'), stmt => Array.from(stmt.iterate(5))));
99
- });
100
- });
@@ -1,66 +0,0 @@
1
- 'use strict';
2
- if (parseInt(process.versions.node) >= 12) {
3
- const threads = require('worker_threads');
4
- const Database = require('../.');
5
-
6
- if (threads.isMainThread) {
7
- describe('Worker Threads', function () {
8
- afterEach(function () {
9
- if (this.db) this.db.close();
10
- return this.cleanup;
11
- });
12
- it('are properly supported', function () {
13
- this.slow(1000);
14
- return new Promise((resolve, reject) => {
15
- const db = this.db = Database(util.next()).defaultSafeIntegers();
16
- expect(db.prepare('select 555').constructor.foo).to.be.undefined;
17
- db.prepare('select 555').constructor.foo = 5;
18
- expect(db.prepare('select 555').constructor.foo).to.equal(5);
19
- const worker = new threads.Worker(__filename);
20
- worker.on('exit', code => reject(new Error(`worker exited with code ${code}`)));
21
- worker.on('error', reject);
22
- worker.on('message', ({ msg, info, data }) => {
23
- try {
24
- if (msg === 'hello') {
25
- db.exec('create table data (a, b)');
26
- worker.postMessage({ msg: 'hello', filename: util.current() });
27
- } else if (msg === 'success') {
28
- const checkedData = db.prepare("select * from data").all();
29
- expect(info.changes).to.equal(checkedData.length);
30
- expect(data).to.not.equal(checkedData);
31
- expect(data).to.deep.equal(checkedData);
32
- expect(db.prepare('select 555').constructor.foo).to.equal(5);
33
- resolve();
34
- this.cleanup = worker.terminate();
35
- } else {
36
- throw new Error('unexpected message from worker');
37
- }
38
- } catch (err) {
39
- reject(err);
40
- this.cleanup = worker.terminate();
41
- }
42
- });
43
- });
44
- });
45
- });
46
- } else {
47
- const { expect } = require('chai');
48
- threads.parentPort.on('message', ({ msg, filename }) => {
49
- if (msg === 'hello') {
50
- const db = Database(filename).defaultSafeIntegers();
51
- expect(db.prepare('select 555').constructor.foo).to.be.undefined;
52
- db.prepare('select 555').constructor.foo = 27;
53
- expect(db.prepare('select 555').constructor.foo).to.equal(27);
54
- const info = db.prepare("insert into data values (1, 2), ('foo', 5.5)").run();
55
- const data = db.prepare("select * from data").all();
56
- expect(info.changes).to.be.a('number');
57
- expect(info.lastInsertRowid).to.be.a('bigint');
58
- expect(data.length).to.equal(2);
59
- threads.parentPort.postMessage({ msg: 'success', info, data });
60
- } else {
61
- throw new Error('unexpected message from main thread');
62
- }
63
- });
64
- threads.parentPort.postMessage({ msg: 'hello' });
65
- }
66
- }