duckdb 0.3.2-dev88.0 → 0.3.2-dev903.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.
package/src/statement.cpp CHANGED
@@ -135,6 +135,10 @@ static Napi::Value convert_chunk(Napi::Env &env, std::vector<std::string> names,
135
135
 
136
136
  for (duckdb::idx_t col_idx = 0; col_idx < chunk.ColumnCount(); col_idx++) {
137
137
  Napi::Value value;
138
+ // set up a new Napi::Object for some data types, e.g. INTERVAL
139
+ Napi::Object object_value;
140
+
141
+ bool is_object_value {false};
138
142
 
139
143
  auto dval = chunk.GetValue(col_idx, row_idx);
140
144
  if (dval.is_null) {
@@ -159,6 +163,13 @@ static Napi::Value convert_chunk(Napi::Env &env, std::vector<std::string> names,
159
163
  case duckdb::LogicalTypeId::HUGEINT: {
160
164
  value = Napi::Number::New(env, dval.GetValue<double>());
161
165
  } break;
166
+ case duckdb::LogicalTypeId::INTERVAL: {
167
+ is_object_value = true;
168
+ object_value = Napi::Object::New(env);
169
+ object_value.Set("months", dval.value_.interval.months);
170
+ object_value.Set("days", dval.value_.interval.days);
171
+ object_value.Set("micros", dval.value_.interval.micros);
172
+ } break;
162
173
  #if (NAPI_VERSION > 4)
163
174
  case duckdb::LogicalTypeId::DATE: {
164
175
  const auto scale = duckdb::Interval::SECS_PER_DAY * duckdb::Interval::MSECS_PER_SEC;
@@ -171,6 +182,9 @@ static Napi::Value convert_chunk(Napi::Env &env, std::vector<std::string> names,
171
182
  case duckdb::LogicalTypeId::VARCHAR: {
172
183
  value = Napi::String::New(env, dval.str_value);
173
184
  } break;
185
+ case duckdb::LogicalTypeId::BOOLEAN: {
186
+ value = Napi::Boolean::New(env, dval.value_.boolean);
187
+ } break;
174
188
  case duckdb::LogicalTypeId::BLOB: {
175
189
  value = Napi::Buffer<char>::Copy(env, dval.str_value.c_str(), dval.str_value.length());
176
190
  } break;
@@ -182,7 +196,11 @@ static Napi::Value convert_chunk(Napi::Env &env, std::vector<std::string> names,
182
196
  .ThrowAsJavaScriptException();
183
197
  return env.Null();
184
198
  }
185
- row_result.Set(node_names[col_idx], value);
199
+ if (is_object_value == true) {
200
+ row_result.Set(node_names[col_idx], object_value);
201
+ } else {
202
+ row_result.Set(node_names[col_idx], value);
203
+ }
186
204
  }
187
205
  result.Set(row_idx, row_result);
188
206
  }
@@ -0,0 +1,37 @@
1
+ var sqlite3 = require("..");
2
+ var assert = require("assert");
3
+
4
+ describe("data type support", function () {
5
+ let db;
6
+ before(function (done) {
7
+ db = new sqlite3.Database(":memory:", done);
8
+ });
9
+
10
+ it("supports BOOLEAN values", function (done) {
11
+ db.run("CREATE TABLE boolean_table (i BOOLEAN)");
12
+ const stmt = db.prepare("INSERT INTO boolean_table VALUES (?)");
13
+ const values = [true, false];
14
+ values.forEach((bool) => {
15
+ stmt.run(bool);
16
+ });
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]));
20
+ done();
21
+ });
22
+ });
23
+ it("supports INTERVAL values", function (done) {
24
+ db.prepare(`SELECT
25
+ INTERVAL 1 MINUTE as minutes,
26
+ INTERVAL 5 DAY as days,
27
+ INTERVAL 4 MONTH as months,
28
+ INTERVAL 4 MONTH + INTERVAL 5 DAY + INTERVAL 1 MINUTE as combined;`).each((err, row) => {
29
+ assert(err === null);
30
+ assert.deepEqual(row.minutes, { months: 0, days: 0, micros: 60 * 1000 * 1000});
31
+ assert.deepEqual(row.days, { months: 0, days: 5, micros: 0});
32
+ assert.deepEqual(row.months, {months: 4, days: 0, micros: 0});
33
+ assert.deepEqual(row.combined, {months: 4, days: 5, micros: 60 * 1000 * 1000});
34
+ done();
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,16 @@
1
+ var sqlite3 = require('..');
2
+ var assert = require('assert');
3
+ var helper = require('./support/helper');
4
+
5
+ describe('can query parquet', function() {
6
+ var db;
7
+
8
+ before(function(done) {
9
+ db = new sqlite3.Database(':memory:', done);
10
+ });
11
+
12
+ it('should be able to read parquet files', function(done) {
13
+ db.run("select * from parquet_scan('../../data/parquet-testing/userdata1.parquet')", done);
14
+ });
15
+
16
+ });