duckdb 0.6.2-dev6.0 → 0.6.2-dev604.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 (32) hide show
  1. package/.mocharc.json +2 -2
  2. package/README.md +17 -0
  3. package/lib/duckdb.d.ts +29 -11
  4. package/lib/duckdb.js +6 -0
  5. package/package.json +1 -1
  6. package/src/duckdb.cpp +17094 -14736
  7. package/src/duckdb.hpp +9807 -9354
  8. package/src/parquet-amalgamation.cpp +35355 -35128
  9. package/src/parquet-amalgamation.hpp +46 -4
  10. package/test/{affected.test.js → affected.test.ts} +8 -10
  11. package/test/{arrow.test.js → arrow.test.ts} +12 -11
  12. package/test/{data_type_support.test.js → data_type_support.test.ts} +36 -35
  13. package/test/{database_fail.test.js → database_fail.test.ts} +25 -24
  14. package/test/{each.test.js → each.test.ts} +10 -9
  15. package/test/{exec.test.js → exec.test.ts} +7 -6
  16. package/test/{extension.test.js → extension.test.ts} +20 -19
  17. package/test/{interrupt.test.js → interrupt.test.ts} +7 -7
  18. package/test/{jsdoc.test.js → jsdoc.test.ts} +19 -20
  19. package/test/{named_columns.test.js → named_columns.test.ts} +4 -6
  20. package/test/{null_error.test.js → null_error.test.ts} +5 -6
  21. package/test/{open_close.test.js → open_close.test.ts} +10 -10
  22. package/test/{parallel_insert.test.js → parallel_insert.test.ts} +6 -7
  23. package/test/{parquet.js → parquet.test.ts} +2 -4
  24. package/test/{pathnames.test.js → pathnames.test.ts} +24 -22
  25. package/test/{prepare.test.js → prepare.test.ts} +53 -50
  26. package/test/{query_result.test.js → query_result.test.ts} +4 -4
  27. package/test/{serialization.test.js → serialization.test.ts} +10 -9
  28. package/test/support/helper.ts +42 -0
  29. package/test/{syntax_error.test.js → syntax_error.test.ts} +4 -4
  30. package/test/{udf.test.js → udf.test.ts} +26 -25
  31. package/test/{unicode.test.js → unicode.test.ts} +23 -22
  32. package/test/support/helper.js +0 -37
@@ -7193,7 +7193,7 @@ public:
7193
7193
  return;
7194
7194
  }
7195
7195
  if (new_size > alloc_len) {
7196
- alloc_len = new_size;
7196
+ alloc_len = NextPowerOfTwo(new_size);
7197
7197
  allocated_data = allocator.Allocate(alloc_len);
7198
7198
  ptr = (char *)allocated_data.get();
7199
7199
  }
@@ -7387,7 +7387,6 @@ namespace duckdb {
7387
7387
  class DbpDecoder {
7388
7388
  public:
7389
7389
  DbpDecoder(const uint8_t *buffer, uint32_t buffer_len) : buffer_((char *)buffer, buffer_len) {
7390
-
7391
7390
  //<block size in values> <number of miniblocks in a block> <total value count> <first value>
7392
7391
  // overall header
7393
7392
  block_value_count = ParquetDecodeUtils::VarintDecode<uint64_t>(buffer_);
@@ -7396,6 +7395,7 @@ public:
7396
7395
  start_value = ParquetDecodeUtils::ZigzagToInt(ParquetDecodeUtils::VarintDecode<int64_t>(buffer_));
7397
7396
 
7398
7397
  // some derivatives
7398
+ D_ASSERT(miniblocks_per_block > 0);
7399
7399
  values_per_miniblock = block_value_count / miniblocks_per_block;
7400
7400
  miniblock_bit_widths = std::unique_ptr<uint8_t[]>(new data_t[miniblocks_per_block]);
7401
7401
 
@@ -7474,6 +7474,17 @@ public:
7474
7474
  }
7475
7475
  start_value = values[batch_size - 1];
7476
7476
  }
7477
+ void Finalize() {
7478
+ if (values_left_in_miniblock == 0) {
7479
+ return;
7480
+ }
7481
+ auto data = unique_ptr<uint32_t[]>(new uint32_t[values_left_in_miniblock]);
7482
+ GetBatch<uint32_t>((char *)data.get(), values_left_in_miniblock);
7483
+ }
7484
+
7485
+ uint64_t TotalValues() {
7486
+ return total_value_count;
7487
+ }
7477
7488
 
7478
7489
  private:
7479
7490
  ByteBuffer buffer_;
@@ -7579,11 +7590,31 @@ public:
7579
7590
 
7580
7591
  virtual unique_ptr<BaseStatistics> Stats(idx_t row_group_idx_p, const std::vector<ColumnChunk> &columns);
7581
7592
 
7593
+ template <class VALUE_TYPE, class CONVERSION>
7594
+ void PlainTemplated(shared_ptr<ByteBuffer> plain_data, uint8_t *defines, uint64_t num_values,
7595
+ parquet_filter_t &filter, idx_t result_offset, Vector &result) {
7596
+ auto result_ptr = FlatVector::GetData<VALUE_TYPE>(result);
7597
+ auto &result_mask = FlatVector::Validity(result);
7598
+ for (idx_t row_idx = 0; row_idx < num_values; row_idx++) {
7599
+ if (HasDefines() && defines[row_idx + result_offset] != max_define) {
7600
+ result_mask.SetInvalid(row_idx + result_offset);
7601
+ continue;
7602
+ }
7603
+ if (filter[row_idx + result_offset]) {
7604
+ VALUE_TYPE val = CONVERSION::PlainRead(*plain_data, *this);
7605
+ result_ptr[row_idx + result_offset] = val;
7606
+ } else { // there is still some data there that we have to skip over
7607
+ CONVERSION::PlainSkip(*plain_data, *this);
7608
+ }
7609
+ }
7610
+ }
7611
+
7582
7612
  protected:
7613
+ Allocator &GetAllocator();
7583
7614
  // readers that use the default Read() need to implement those
7584
7615
  virtual void Plain(shared_ptr<ByteBuffer> plain_data, uint8_t *defines, idx_t num_values, parquet_filter_t &filter,
7585
7616
  idx_t result_offset, Vector &result);
7586
- virtual void Dictionary(shared_ptr<ByteBuffer> dictionary_data, idx_t num_entries);
7617
+ virtual void Dictionary(shared_ptr<ResizeableBuffer> dictionary_data, idx_t num_entries);
7587
7618
  virtual void Offsets(uint32_t *offsets, uint8_t *defines, idx_t num_values, parquet_filter_t &filter,
7588
7619
  idx_t result_offset, Vector &result);
7589
7620
 
@@ -7591,6 +7622,11 @@ protected:
7591
7622
  virtual void DictReference(Vector &result);
7592
7623
  virtual void PlainReference(shared_ptr<ByteBuffer>, Vector &result);
7593
7624
 
7625
+ virtual void PrepareDeltaLengthByteArray(ResizeableBuffer &buffer);
7626
+ virtual void PrepareDeltaByteArray(ResizeableBuffer &buffer);
7627
+ virtual void DeltaByteArray(uint8_t *defines, idx_t num_values, parquet_filter_t &filter, idx_t result_offset,
7628
+ Vector &result);
7629
+
7594
7630
  // applies any skips that were registered using Skip()
7595
7631
  virtual void ApplyPendingSkips(idx_t num_values);
7596
7632
 
@@ -7611,10 +7647,13 @@ protected:
7611
7647
 
7612
7648
  ParquetReader &reader;
7613
7649
  LogicalType type;
7650
+ unique_ptr<Vector> byte_array_data;
7614
7651
 
7615
7652
  idx_t pending_skips = 0;
7616
7653
 
7617
7654
  private:
7655
+ void AllocateBlock(idx_t size);
7656
+ void AllocateCompressed(idx_t size);
7618
7657
  void PrepareRead(parquet_filter_t &filter);
7619
7658
  void PreparePage(PageHeader &page_hdr);
7620
7659
  void PrepareDataPage(PageHeader &page_hdr);
@@ -7630,12 +7669,14 @@ private:
7630
7669
 
7631
7670
  shared_ptr<ResizeableBuffer> block;
7632
7671
 
7672
+ ResizeableBuffer compressed_buffer;
7633
7673
  ResizeableBuffer offset_buffer;
7634
7674
 
7635
7675
  unique_ptr<RleBpDecoder> dict_decoder;
7636
7676
  unique_ptr<RleBpDecoder> defined_decoder;
7637
7677
  unique_ptr<RleBpDecoder> repeated_decoder;
7638
7678
  unique_ptr<DbpDecoder> dbp_decoder;
7679
+ unique_ptr<RleBpDecoder> rle_decoder;
7639
7680
 
7640
7681
  // dummies for Skip()
7641
7682
  parquet_filter_t none_filter;
@@ -7908,7 +7949,8 @@ public:
7908
7949
  idx_t max_repeat = 0, idx_t max_define = 1,
7909
7950
  bool can_have_nulls = true);
7910
7951
 
7911
- virtual unique_ptr<ColumnWriterState> InitializeWriteState(duckdb_parquet::format::RowGroup &row_group) = 0;
7952
+ virtual unique_ptr<ColumnWriterState> InitializeWriteState(duckdb_parquet::format::RowGroup &row_group,
7953
+ Allocator &allocator) = 0;
7912
7954
 
7913
7955
  //! indicates whether the write need to analyse the data before preparing it
7914
7956
  virtual bool HasAnalyze() {
@@ -1,22 +1,22 @@
1
- var sqlite3 = require('..');
2
- var assert = require('assert');
1
+ import * as sqlite3 from '..';
2
+ import * as assert from 'assert';
3
3
 
4
4
  describe('query properties', function() {
5
- var db;
5
+ var db: sqlite3.Database;
6
6
  before(function(done) {
7
7
  db = new sqlite3.Database(':memory:');
8
8
  db.run("CREATE TABLE foo (id INT, txt TEXT)", done);
9
9
  });
10
10
 
11
- /*
12
- it('should return the correct lastID', function(done) {
11
+ it.skip('should return the correct lastID', function(done) {
13
12
  var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)");
14
13
  var j = 1;
15
14
  for (var i = 0; i < 5000; i++) {
16
- stmt.run(i, "demo", function(err) {
15
+ stmt.run(i, "demo", function(err: null | Error) {
17
16
  if (err) throw err;
18
17
  // Relies on SQLite's row numbering to be gapless and starting
19
18
  // from 1.
19
+ // @ts-ignore
20
20
  assert.equal(j++, this.lastID);
21
21
  });
22
22
  }
@@ -24,13 +24,11 @@ describe('query properties', function() {
24
24
  });
25
25
 
26
26
 
27
- it('should return the correct changes count', function(done) {
28
- db.run("UPDATE foo SET id = id + 1 WHERE id % 2 = 0", function(err) {
27
+ it.skip('should return the correct changes count', function(done) {
28
+ db.run("UPDATE foo SET id = id + 1 WHERE id % 2 = 0", function(err: null | Error) {
29
29
  if (err) throw err;
30
30
  // FIXME assert.equal(2500, this.changes);
31
31
  done();
32
32
  });
33
33
  });
34
- */
35
-
36
34
  });
@@ -1,11 +1,12 @@
1
- var duckdb = require('..');
2
- var assert = require('assert');
3
- var fs = require('fs');
1
+ import * as duckdb from '..';
2
+ import * as assert from 'assert';
3
+ import * as fs from 'fs';
4
+ import {QueryResult} from "..";
4
5
 
5
6
  describe('arrow IPC API fails neatly when extension not loaded', function() {
6
7
  // Note: arrow IPC api requires the arrow extension to be loaded. The tests for this functionality reside in:
7
8
  // https://github.com/duckdblabs/arrow
8
- let db;
9
+ let db: duckdb.Database;
9
10
  let conn;
10
11
  before((done) => {
11
12
  db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"}, () => {
@@ -20,13 +21,13 @@ describe('arrow IPC API fails neatly when extension not loaded', function() {
20
21
  db.arrowIPCStream(query).then(
21
22
  () => Promise.reject(new Error('Expected method to reject.')),
22
23
  err => {
23
- assert(err.message.includes("Catalog Error: Function with name to_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"))
24
+ assert.ok(err.message.includes("Catalog Error: Function with name to_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"))
24
25
  }
25
26
  );
26
27
 
27
- db.arrowIPCAll(`SELECT * FROM ipc_table`, function (err, result) {
28
+ db.arrowIPCAll(`SELECT * FROM ipc_table`, function (err: null | Error, result: QueryResult) {
28
29
  if (err) {
29
- assert(err.message.includes("Catalog Error: Function with name to_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"))
30
+ assert.ok(err.message.includes("Catalog Error: Function with name to_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"))
30
31
  } else {
31
32
  assert.fail("Expected error");
32
33
  }
@@ -36,16 +37,16 @@ describe('arrow IPC API fails neatly when extension not loaded', function() {
36
37
  });
37
38
 
38
39
  it('register buffer should be disabled currently', function(done) {
39
- db.register_buffer("test", [new Uint8Array(new ArrayBuffer(10))], true, (err) => {
40
- assert(err)
41
- assert(err.includes("Function with name scan_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"));
40
+ db.register_buffer("test", [new Uint8Array(new ArrayBuffer(10))], true, (err: null | Error) => {
41
+ assert.ok(err)
42
+ assert.ok(err.toString().includes("Function with name scan_arrow_ipc is not on the catalog, but it exists in the arrow extension. To Install and Load the extension, run: INSTALL arrow; LOAD arrow;"));
42
43
  done()
43
44
  });
44
45
  });
45
46
 
46
47
  it('unregister will silently do nothing', function(done) {
47
48
  db.unregister_buffer("test", (err) => {
48
- assert(!err)
49
+ assert.ok(!err)
49
50
  done()
50
51
  });
51
52
  });
@@ -1,8 +1,9 @@
1
- var sqlite3 = require("..");
2
- var assert = require("assert");
1
+ import * as sqlite3 from "..";
2
+ import * as assert from "assert";
3
+ import {RowData, TableData} from "..";
3
4
 
4
5
  describe("data type support", function () {
5
- let db;
6
+ let db: sqlite3.Database;
6
7
  before(function (done) {
7
8
  db = new sqlite3.Database(":memory:", done);
8
9
  });
@@ -14,9 +15,9 @@ describe("data type support", function () {
14
15
  values.forEach((bool) => {
15
16
  stmt.run(bool);
16
17
  });
17
- db.prepare("SELECT i from boolean_table;").all((err, res) => {
18
- assert(err === null);
19
- assert(res.every((v, i) => v.i === values[i]));
18
+ db.prepare("SELECT i from boolean_table;").all((err: null | Error, res: TableData) => {
19
+ assert.equal(err, null);
20
+ assert.ok(res.every((v, i) => v.i === values[i]));
20
21
  done();
21
22
  });
22
23
  });
@@ -26,9 +27,9 @@ describe("data type support", function () {
26
27
  const stmt = db.prepare("INSERT INTO integer_table VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
27
28
 
28
29
  // Numerical limits
29
- signedMinValue = (bitWidth) => Math.max(-(2**(bitWidth-1)-1)-1, Number.MIN_SAFE_INTEGER);
30
- signedMaxValue = (bitWidth) => Math.min(2**(bitWidth-1)-1, Number.MAX_SAFE_INTEGER);
31
- unsignedMaxValue = (bitWidth) => Math.min(2**(bitWidth)-1, Number.MAX_SAFE_INTEGER);
30
+ let signedMinValue = (bitWidth: number) => Math.max(-(2**(bitWidth-1)-1)-1, Number.MIN_SAFE_INTEGER);
31
+ let signedMaxValue = (bitWidth: number) => Math.min(2**(bitWidth-1)-1, Number.MAX_SAFE_INTEGER);
32
+ let unsignedMaxValue = (bitWidth: number) => Math.min(2**(bitWidth)-1, Number.MAX_SAFE_INTEGER);
32
33
  let minValues = [signedMinValue(8), signedMinValue(16), signedMinValue(32), signedMinValue(64), 0, 0, 0, 0];
33
34
  let maxValues = [signedMinValue(8), signedMinValue(16), signedMinValue(32), signedMinValue(64), unsignedMaxValue(8), unsignedMaxValue(16), unsignedMaxValue(32), unsignedMaxValue(64)];
34
35
 
@@ -36,11 +37,11 @@ describe("data type support", function () {
36
37
  stmt.run(...minValues);
37
38
  stmt.run(...maxValues);
38
39
 
39
- db.prepare("SELECT * from integer_table;").all((err, res) => {
40
- assert(err === null);
41
- assert(res.length === 2);
42
- assert(Object.entries(res[0]).length === 8);
43
- assert(Object.entries(res[1]).length === 8);
40
+ db.prepare("SELECT * from integer_table;").all((err: null | Error, res: TableData) => {
41
+ assert.equal(err, null);
42
+ assert.equal(res.length, 2);
43
+ assert.equal(Object.entries(res[0]).length, 8);
44
+ assert.equal(Object.entries(res[1]).length, 8);
44
45
  assert.deepEqual(Object.entries(res[0]).map(v => v[1]), minValues);
45
46
  assert.deepEqual(Object.entries(res[1]).map(v => v[1]), maxValues);
46
47
  done();
@@ -54,8 +55,8 @@ describe("data type support", function () {
54
55
  INTERVAL 5 DAY as days,
55
56
  INTERVAL 4 MONTH as months,
56
57
  INTERVAL 4 MONTH + INTERVAL 5 DAY + INTERVAL 1 MINUTE as combined;`
57
- ).each((err, row) => {
58
- assert(err === null);
58
+ ).each((err: null | Error, row: RowData) => {
59
+ assert.equal(err, null);
59
60
  assert.deepEqual(row.minutes, {
60
61
  months: 0,
61
62
  days: 0,
@@ -74,7 +75,7 @@ describe("data type support", function () {
74
75
 
75
76
  it("supports STRUCT values", function (done) {
76
77
  db.prepare(`SELECT {'x': 1, 'y': 2, 'z': {'a': 'b'}} as struct`).each(
77
- (err, row) => {
78
+ (err: null | Error, row: RowData) => {
78
79
  assert.deepEqual(row.struct, { x: 1, y: 2, z: { a: "b" } });
79
80
  done();
80
81
  }
@@ -86,8 +87,8 @@ describe("data type support", function () {
86
87
  db.run("INSERT INTO struct_table VALUES ({'a': 'hello', 'b': true})");
87
88
  db.run("INSERT INTO struct_table VALUES ({'a': 'goodbye', 'b': false})");
88
89
  db.run("INSERT INTO struct_table VALUES ({'a': 'aloha', 'b': NULL})");
89
- db.prepare("SELECT s from struct_table;").all((err, res) => {
90
- assert(err === null);
90
+ db.prepare("SELECT s from struct_table;").all((err: null | Error, res: RowData) => {
91
+ assert.equal(err, null);
91
92
  assert.deepEqual(res, [
92
93
  { s: { a: "hello", b: true } },
93
94
  { s: { a: "goodbye", b: false } },
@@ -106,8 +107,8 @@ describe("data type support", function () {
106
107
  {'a': 43, 'b': NULL}
107
108
  ] l UNION ALL SELECT NULL`
108
109
  );
109
- db.prepare("SELECT l from recursive_struct").all((err, res) => {
110
- assert(err === null);
110
+ db.prepare("SELECT l from recursive_struct").all((err: null | Error, res: RowData) => {
111
+ assert.equal(err, null);
111
112
  assert.deepEqual(res, [
112
113
  {
113
114
  l: [
@@ -135,32 +136,32 @@ describe("data type support", function () {
135
136
  });
136
137
 
137
138
  it("supports LIST values", function (done) {
138
- db.prepare(`SELECT ['duck', 'duck', 'goose'] as list`).each((err, row) => {
139
- assert(err === null);
139
+ db.prepare(`SELECT ['duck', 'duck', 'goose'] as list`).each((err: null | Error, row: RowData) => {
140
+ assert.equal(err, null);
140
141
  assert.deepEqual(row.list, ["duck", "duck", "goose"]);
141
142
  done();
142
143
  });
143
144
  });
144
145
 
145
146
  it("supports LIST with NULL values", function (done) {
146
- db.prepare(`SELECT ['duck', 'duck', NULL] as list`).each((err, row) => {
147
- assert(err === null);
147
+ db.prepare(`SELECT ['duck', 'duck', NULL] as list`).each((err: null | Error, row: RowData) => {
148
+ assert.equal(err, null);
148
149
  assert.deepEqual(row.list, ["duck", "duck", null]);
149
150
  done();
150
151
  });
151
152
  });
152
153
 
153
154
  it("supports DATE values", function (done) {
154
- db.prepare(`SELECT '2021-01-01'::DATE as dt;`).each((err, row) => {
155
- assert(err === null);
155
+ db.prepare(`SELECT '2021-01-01'::DATE as dt;`).each((err: null | Error, row: RowData) => {
156
+ assert.equal(err, null);
156
157
  assert.deepEqual(row.dt, new Date(Date.UTC(2021, 0, 1)));
157
158
  done();
158
159
  });
159
160
  });
160
161
  it("supports TIMESTAMP values", function (done) {
161
162
  db.prepare(`SELECT '2021-01-01T00:00:00'::TIMESTAMP as ts;`).each(
162
- (err, row) => {
163
- assert(err === null);
163
+ (err: null | Error, row: RowData) => {
164
+ assert.equal(err, null);
164
165
  assert.deepEqual(row.ts, new Date(Date.UTC(2021, 0, 1)));
165
166
  done();
166
167
  }
@@ -168,8 +169,8 @@ describe("data type support", function () {
168
169
  });
169
170
  it("supports TIMESTAMP WITH TIME ZONE values", function (done) {
170
171
  db.prepare(`SELECT '2021-01-01T00:00:00Z'::TIMESTAMPTZ as tstz;`).each(
171
- (err, row) => {
172
- assert(err === null);
172
+ (err: null | Error, row: RowData) => {
173
+ assert.equal(err, null);
173
174
  assert.deepEqual(row.tstz, new Date(Date.UTC(2021, 0, 1)));
174
175
  done();
175
176
  }
@@ -182,14 +183,14 @@ describe("data type support", function () {
182
183
  values.forEach((d) => {
183
184
  stmt.run(d);
184
185
  });
185
- db.prepare("SELECT d from decimal_table;").all((err, res) => {
186
- assert(err === null);
187
- assert(res.every((v, i) => v.d === values[i]));
186
+ db.prepare("SELECT d from decimal_table;").all((err: null | Error, res: TableData) => {
187
+ assert.equal(err, null);
188
+ assert.ok(res.every((v, i) => v.d === values[i]));
188
189
  done();
189
190
  });
190
191
  });
191
192
  it("converts unsupported data types to strings", function(done) {
192
- db.all("SELECT CAST('11:10:10' AS TIME) as time", function(err, rows) {
193
+ db.all("SELECT CAST('11:10:10' AS TIME) as time", function(err: null | Error, rows: TableData) {
193
194
  assert.equal(rows[0].time, '11:10:10');
194
195
  done();
195
196
  });
@@ -1,24 +1,27 @@
1
- var sqlite3 = require('..');
2
- var assert = require('assert');
1
+ import * as sqlite3 from '..';
2
+ import * as assert from 'assert';
3
+ import {DuckDbError, RowData} from "..";
3
4
 
4
5
  describe('error handling', function() {
5
- var db;
6
+ var db: sqlite3.Database;
6
7
  before(function(done) {
7
8
  db = new sqlite3.Database(':memory:', done);
8
9
  });
9
10
 
10
11
  it('throw when calling Database() without new', function() {
11
12
  assert.throws(function() {
13
+ // @ts-ignore
12
14
  sqlite3.Database(':memory:');
13
15
  }, (/Class constructors cannot be invoked without 'new'/));
14
16
 
15
17
  assert.throws(function() {
18
+ // @ts-ignore
16
19
  sqlite3.Statement();
17
20
  }, (/Class constructors cannot be invoked without 'new'/));
18
21
  });
19
22
 
20
23
  it('should error when calling Database#each on a missing table', function(done) {
21
- db.each('SELECT id, txt FROM foo', function(err, row) {
24
+ db.each('SELECT id, txt FROM foo', function(err: null | DuckDbError, row: RowData) {
22
25
  if (err) {
23
26
  assert.equal(err.message.includes('does not exist'), 1);
24
27
  assert.equal(err.errno, sqlite3.ERROR);
@@ -30,7 +33,7 @@ describe('error handling', function() {
30
33
  });
31
34
 
32
35
  it('Database#all prepare fail', function(done) {
33
- db.all('SELECT id, txt FROM foo', function(err, row) {
36
+ db.all('SELECT id, txt FROM foo', function(err: null | DuckDbError, row: RowData) {
34
37
  if (err) {
35
38
  assert.equal(err.message.includes('does not exist'), 1);
36
39
  assert.equal(err.errno, sqlite3.ERROR);
@@ -42,7 +45,7 @@ describe('error handling', function() {
42
45
  });
43
46
 
44
47
  it('Database#run prepare fail', function(done) {
45
- db.run('SELECT id, txt FROM foo', function(err, row) {
48
+ db.run('SELECT id, txt FROM foo', function(err: null | DuckDbError, row: void) {
46
49
  if (err) {
47
50
  assert.equal(err.message.includes('does not exist'), 1);
48
51
  assert.equal(err.errno, sqlite3.ERROR);
@@ -53,11 +56,10 @@ describe('error handling', function() {
53
56
  });
54
57
  });
55
58
 
56
- /*
57
- it('Database#each prepare fail', function(done) {
58
- db.each('SELECT id, txt FROM foo', function(err, row) {
59
+ it.skip('Database#each prepare fail', function(done) {
60
+ db.each('SELECT id, txt FROM foo', function(err: null | DuckDbError, row: RowData) {
59
61
  assert.ok(false, "this should not be called");
60
- }, function(err, num) {
62
+ }, function(err: null | DuckDbError, num: RowData) {
61
63
  if (err) {
62
64
  assert.equal(err.message.includes('does not exist'), 1);
63
65
  assert.equal(err.errno, sqlite3.ERROR);
@@ -67,9 +69,9 @@ describe('error handling', function() {
67
69
  }
68
70
  });
69
71
  });
70
- */
72
+
71
73
  it('Database#each prepare fail without completion handler', function(done) {
72
- db.each('SELECT id, txt FROM foo', function(err, row) {
74
+ db.each('SELECT id, txt FROM foo', function(err: null | DuckDbError, row: RowData) {
73
75
  if (err) {
74
76
  assert.equal(err.message.includes('does not exist'), 1);
75
77
  assert.equal(err.errno, sqlite3.ERROR);
@@ -79,9 +81,9 @@ describe('error handling', function() {
79
81
  }
80
82
  });
81
83
  });
82
- /*
83
- it('Database#get prepare fail with param binding', function(done) {
84
- db.get('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) {
84
+
85
+ it.skip('Database#get prepare fail with param binding', function(done) {
86
+ db.get('SELECT id, txt FROM foo WHERE id = ?', 1, function(err: null | DuckDbError, row: RowData) {
85
87
  if (err) {
86
88
  assert.equal(err.message.includes('does not exist'), 1);
87
89
  assert.equal(err.errno, sqlite3.ERROR);
@@ -91,9 +93,9 @@ describe('error handling', function() {
91
93
  }
92
94
  });
93
95
  });
94
- */
96
+
95
97
  it('Database#all prepare fail with param binding', function(done) {
96
- db.all('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) {
98
+ db.all('SELECT id, txt FROM foo WHERE id = ?', 1, function(err: null | DuckDbError, row: RowData) {
97
99
  if (err) {
98
100
  assert.equal(err.message.includes('does not exist'), 1);
99
101
  assert.equal(err.errno, sqlite3.ERROR);
@@ -105,7 +107,7 @@ describe('error handling', function() {
105
107
  });
106
108
 
107
109
  it('Database#run prepare fail with param binding', function(done) {
108
- db.run('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) {
110
+ db.run('SELECT id, txt FROM foo WHERE id = ?', 1, function(err: null | DuckDbError, row: void) {
109
111
  if (err) {
110
112
  assert.equal(err.message.includes('does not exist'), 1);
111
113
  assert.equal(err.errno, sqlite3.ERROR);
@@ -116,11 +118,10 @@ describe('error handling', function() {
116
118
  });
117
119
  });
118
120
 
119
- /*
120
- it('Database#each prepare fail with param binding', function(done) {
121
- db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) {
121
+ it.skip('Database#each prepare fail with param binding', function(done) {
122
+ db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err: null | DuckDbError, row: RowData) {
122
123
  assert.ok(false, "this should not be called");
123
- }, function(err, num) {
124
+ }, function(err: null | DuckDbError, row: RowData) {
124
125
  if (err) {
125
126
  assert.equal(err.message.includes('does not exist'), 1);
126
127
  assert.equal(err.errno, sqlite3.ERROR);
@@ -130,9 +131,9 @@ describe('error handling', function() {
130
131
  }
131
132
  });
132
133
  });
133
- */
134
+
134
135
  it('Database#each prepare fail with param binding without completion handler', function(done) {
135
- db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err, row) {
136
+ db.each('SELECT id, txt FROM foo WHERE id = ?', 1, function(err: null | DuckDbError, row: RowData) {
136
137
  if (err) {
137
138
  assert.equal(err.message.includes('does not exist'), 1);
138
139
  assert.equal(err.errno, sqlite3.ERROR);
@@ -1,8 +1,9 @@
1
- var sqlite3 = require('..');
2
- var assert = require('assert');
1
+ import * as sqlite3 from '..';
2
+ import * as assert from 'assert';
3
+ import {RowData} from "..";
3
4
 
4
5
  describe('each', function() {
5
- var db;
6
+ var db: sqlite3.Database;
6
7
  before(function(done) {
7
8
  db = new sqlite3.Database('test/support/big.db', done);
8
9
  });
@@ -12,7 +13,7 @@ describe('each', function() {
12
13
  var retrieved = 0;
13
14
 
14
15
 
15
- db.each('SELECT id, txt FROM foo WHERE ROWID < ?', total, function(err, row) {
16
+ db.each('SELECT id, txt FROM foo WHERE ROWID < ?', total, function(err: null | Error, row: RowData) {
16
17
  if (err) throw err;
17
18
  retrieved++;
18
19
 
@@ -22,18 +23,18 @@ describe('each', function() {
22
23
  }
23
24
  });
24
25
  });
25
- /*
26
- it('Statement#each with complete callback', function(done) {
26
+
27
+ it.skip('Statement#each with complete callback', function(done) {
27
28
  var total = 10000;
28
29
  var retrieved = 0;
29
30
 
30
- db.each('SELECT id, txt FROM foo WHERE ROWID < ?', total, function(err, row) {
31
+ db.each('SELECT id, txt FROM foo WHERE ROWID < ?', total, function(err: null | Error, row: RowData) {
31
32
  if (err) throw err;
32
33
  retrieved++;
33
- }, function(err, num) {
34
+ }, function(err: null | Error, num: RowData) {
34
35
  assert.equal(retrieved, num);
35
36
  assert.equal(retrieved, total, "Only retrieved " + retrieved + " out of " + total + " rows.");
36
37
  done();
37
38
  });
38
- });*/
39
+ });
39
40
  });
@@ -1,23 +1,24 @@
1
- var sqlite3 = require('..');
2
- var assert = require('assert');
3
- var fs = require('fs');
1
+ import * as sqlite3 from '..';
2
+ import * as assert from 'assert';
3
+ import * as fs from 'fs';
4
+ import {TableData} from "..";
4
5
 
5
6
  describe('exec', function() {
6
- var db;
7
+ var db: sqlite3.Database;
7
8
  before(function(done) {
8
9
  db = new sqlite3.Database(':memory:', done);
9
10
  });
10
11
 
11
12
  it('Database#exec', function(done) {
12
13
  var sql = fs.readFileSync('test/support/script.sql', 'utf8');
13
- db.exec(sql, function(err) {
14
+ db.exec(sql, function(err: null | Error) {
14
15
  if (err) throw err;
15
16
  done();
16
17
  });
17
18
  });
18
19
 
19
20
  it('retrieve database structure', function(done) {
20
- db.all("SELECT type, name FROM sqlite_master ORDER BY type, name", function(err, rows) {
21
+ db.all("SELECT type, name FROM sqlite_master ORDER BY type, name", function(err: null | Error, rows: TableData) {
21
22
  if (err) throw err;
22
23
  assert.deepEqual(rows, [
23
24
  // { type: 'index', name: 'grid_key_lookup' },