@duckdb/node-api 1.2.0-alpha.14 → 1.2.0-alpha.15

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/README.md CHANGED
@@ -644,7 +644,7 @@ await connection.run(
644
644
  `create or replace table target_table(i integer, v varchar)`
645
645
  );
646
646
 
647
- const appender = await connection.createAppender('main', 'target_table');
647
+ const appender = await connection.createAppender('target_table');
648
648
 
649
649
  appender.appendInteger(42);
650
650
  appender.appendVarchar('duck');
@@ -670,7 +670,7 @@ await connection.run(
670
670
  `create or replace table target_table(i integer, v varchar)`
671
671
  );
672
672
 
673
- const appender = await connection.createAppender('main', 'target_table');
673
+ const appender = await connection.createAppender('target_table');
674
674
 
675
675
  const chunk = DuckDBDataChunk.create([INTEGER, VARCHAR]);
676
676
  chunk.setColumns([
@@ -1,7 +1,7 @@
1
1
  import duckdb from '@duckdb/node-bindings';
2
2
  import { DuckDBDataChunk } from './DuckDBDataChunk';
3
- import { DuckDBType } from './DuckDBType';
4
- import { DuckDBDateValue, DuckDBIntervalValue, DuckDBTimestampValue, DuckDBTimeValue } from './values';
3
+ import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBStructType, DuckDBType } from './DuckDBType';
4
+ import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUUIDValue, DuckDBValue } from './values';
5
5
  export declare class DuckDBAppender {
6
6
  private readonly appender;
7
7
  constructor(appender: duckdb.Appender);
@@ -22,14 +22,28 @@ export declare class DuckDBAppender {
22
22
  appendUInteger(value: number): void;
23
23
  appendUBigInt(value: bigint): void;
24
24
  appendUHugeInt(value: bigint): void;
25
+ appendDecimal(value: DuckDBDecimalValue): void;
25
26
  appendFloat(value: number): void;
26
27
  appendDouble(value: number): void;
27
28
  appendDate(value: DuckDBDateValue): void;
28
29
  appendTime(value: DuckDBTimeValue): void;
30
+ appendTimeTZ(value: DuckDBTimeTZValue): void;
29
31
  appendTimestamp(value: DuckDBTimestampValue): void;
32
+ appendTimestampTZ(value: DuckDBTimestampTZValue): void;
33
+ appendTimestampSeconds(value: DuckDBTimestampSecondsValue): void;
34
+ appendTimestampMilliseconds(value: DuckDBTimestampMillisecondsValue): void;
35
+ appendTimestampNanoseconds(value: DuckDBTimestampNanosecondsValue): void;
30
36
  appendInterval(value: DuckDBIntervalValue): void;
31
37
  appendVarchar(value: string): void;
32
38
  appendBlob(value: Uint8Array): void;
39
+ appendEnum(value: string, type: DuckDBEnumType): void;
40
+ appendList(value: DuckDBListValue, type: DuckDBListType): void;
41
+ appendStruct(value: DuckDBStructValue, type: DuckDBStructType): void;
42
+ appendArray(value: DuckDBArrayValue, type: DuckDBArrayType): void;
43
+ appendUUID(value: DuckDBUUIDValue): void;
44
+ appendBit(value: DuckDBBitValue): void;
45
+ appendVarInt(value: bigint): void;
33
46
  appendNull(): void;
47
+ appendValue(value: DuckDBValue, type: DuckDBType): void;
34
48
  appendDataChunk(dataChunk: DuckDBDataChunk): void;
35
49
  }
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DuckDBAppender = void 0;
7
7
  const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
8
+ const createValue_1 = require("./createValue");
8
9
  const DuckDBLogicalType_1 = require("./DuckDBLogicalType");
10
+ const DuckDBType_1 = require("./DuckDBType");
9
11
  class DuckDBAppender {
10
12
  appender;
11
13
  constructor(appender) {
@@ -62,7 +64,10 @@ class DuckDBAppender {
62
64
  appendUHugeInt(value) {
63
65
  node_bindings_1.default.append_uhugeint(this.appender, value);
64
66
  }
65
- // TODO: append DECIMAL?
67
+ appendDecimal(value) {
68
+ // The width and scale of the DECIMAL type here aren't actually used.
69
+ this.appendValue(value, (0, DuckDBType_1.DECIMAL)(value.width, value.scale));
70
+ }
66
71
  appendFloat(value) {
67
72
  node_bindings_1.default.append_float(this.appender, value);
68
73
  }
@@ -75,11 +80,24 @@ class DuckDBAppender {
75
80
  appendTime(value) {
76
81
  node_bindings_1.default.append_time(this.appender, value);
77
82
  }
83
+ appendTimeTZ(value) {
84
+ this.appendValue(value, DuckDBType_1.TIMETZ);
85
+ }
78
86
  appendTimestamp(value) {
79
87
  node_bindings_1.default.append_timestamp(this.appender, value);
80
88
  }
81
- // TODO: append TIMESTAMPS_S/_MS/_NS?
82
- // TODO: append TIME_TZ/TIMESTAMP_TZ?
89
+ appendTimestampTZ(value) {
90
+ this.appendValue(value, DuckDBType_1.TIMESTAMPTZ);
91
+ }
92
+ appendTimestampSeconds(value) {
93
+ this.appendValue(value, DuckDBType_1.TIMESTAMP_S);
94
+ }
95
+ appendTimestampMilliseconds(value) {
96
+ this.appendValue(value, DuckDBType_1.TIMESTAMP_MS);
97
+ }
98
+ appendTimestampNanoseconds(value) {
99
+ this.appendValue(value, DuckDBType_1.TIMESTAMP_NS);
100
+ }
83
101
  appendInterval(value) {
84
102
  node_bindings_1.default.append_interval(this.appender, value);
85
103
  }
@@ -89,13 +107,35 @@ class DuckDBAppender {
89
107
  appendBlob(value) {
90
108
  node_bindings_1.default.append_blob(this.appender, value);
91
109
  }
92
- // TODO: append ENUM?
93
- // TODO: append nested types? (ARRAY, LIST, STRUCT, MAP, UNION)
94
- // TODO: append UUID?
95
- // TODO: append BIT?
110
+ appendEnum(value, type) {
111
+ this.appendValue(value, type);
112
+ }
113
+ appendList(value, type) {
114
+ this.appendValue(value, type);
115
+ }
116
+ appendStruct(value, type) {
117
+ this.appendValue(value, type);
118
+ }
119
+ // TODO: MAP (when DuckDB C API supports creating MAP values)
120
+ appendArray(value, type) {
121
+ this.appendValue(value, type);
122
+ }
123
+ // TODO: UNION (when DuckDB C API supports creating UNION values)
124
+ appendUUID(value) {
125
+ this.appendValue(value, DuckDBType_1.UUID);
126
+ }
127
+ appendBit(value) {
128
+ this.appendValue(value, DuckDBType_1.BIT);
129
+ }
130
+ appendVarInt(value) {
131
+ this.appendValue(value, DuckDBType_1.VARINT);
132
+ }
96
133
  appendNull() {
97
134
  node_bindings_1.default.append_null(this.appender);
98
135
  }
136
+ appendValue(value, type) {
137
+ node_bindings_1.default.append_value(this.appender, (0, createValue_1.createValue)(type, value));
138
+ }
99
139
  appendDataChunk(dataChunk) {
100
140
  node_bindings_1.default.append_data_chunk(this.appender, dataChunk.chunk);
101
141
  }
@@ -30,5 +30,5 @@ export declare class DuckDBConnection {
30
30
  startStream(sql: string, values?: DuckDBValue[] | Record<string, DuckDBValue>, types?: DuckDBType[] | Record<string, DuckDBType | undefined>): Promise<DuckDBPendingResult>;
31
31
  prepare(sql: string): Promise<DuckDBPreparedStatement>;
32
32
  extractStatements(sql: string): Promise<DuckDBExtractedStatements>;
33
- createAppender(schema: string, table: string): Promise<DuckDBAppender>;
33
+ createAppender(table: string, schema?: string | null, catalog?: string | null): Promise<DuckDBAppender>;
34
34
  }
@@ -98,8 +98,8 @@ class DuckDBConnection {
98
98
  }
99
99
  return new DuckDBExtractedStatements_1.DuckDBExtractedStatements(this.connection, extracted_statements, statement_count);
100
100
  }
101
- async createAppender(schema, table) {
102
- return new DuckDBAppender_1.DuckDBAppender(node_bindings_1.default.appender_create(this.connection, schema, table));
101
+ async createAppender(table, schema, catalog) {
102
+ return new DuckDBAppender_1.DuckDBAppender(node_bindings_1.default.appender_create_ext(this.connection, catalog ?? null, schema ?? null, table));
103
103
  }
104
104
  }
105
105
  exports.DuckDBConnection = DuckDBConnection;
@@ -3,10 +3,10 @@ import { DuckDBMaterializedResult } from './DuckDBMaterializedResult';
3
3
  import { DuckDBPendingResult } from './DuckDBPendingResult';
4
4
  import { DuckDBResult } from './DuckDBResult';
5
5
  import { DuckDBResultReader } from './DuckDBResultReader';
6
- import { DuckDBArrayType, DuckDBListType, DuckDBStructType, DuckDBType } from './DuckDBType';
6
+ import { DuckDBArrayType, DuckDBEnumType, DuckDBListType, DuckDBStructType, DuckDBType } from './DuckDBType';
7
7
  import { DuckDBTypeId } from './DuckDBTypeId';
8
8
  import { StatementType } from './enums';
9
- import { DuckDBArrayValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBStructValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBValue } from './values';
9
+ import { DuckDBArrayValue, DuckDBBitValue, DuckDBDateValue, DuckDBDecimalValue, DuckDBIntervalValue, DuckDBListValue, DuckDBStructValue, DuckDBTimestampMillisecondsValue, DuckDBTimestampNanosecondsValue, DuckDBTimestampSecondsValue, DuckDBTimestampTZValue, DuckDBTimestampValue, DuckDBTimeTZValue, DuckDBTimeValue, DuckDBUUIDValue, DuckDBValue } from './values';
10
10
  export declare class DuckDBPreparedStatement {
11
11
  private readonly prepared_statement;
12
12
  constructor(prepared_statement: duckdb.PreparedStatement);
@@ -28,6 +28,7 @@ export declare class DuckDBPreparedStatement {
28
28
  bindUInteger(parameterIndex: number, value: number): void;
29
29
  bindUBigInt(parameterIndex: number, value: bigint): void;
30
30
  bindUHugeInt(parameterIndex: number, value: bigint): void;
31
+ bindVarInt(parameterIndex: number, value: bigint): void;
31
32
  bindDecimal(parameterIndex: number, value: DuckDBDecimalValue): void;
32
33
  bindFloat(parameterIndex: number, value: number): void;
33
34
  bindDouble(parameterIndex: number, value: number): void;
@@ -36,12 +37,18 @@ export declare class DuckDBPreparedStatement {
36
37
  bindTimeTZ(parameterIndex: number, value: DuckDBTimeTZValue): void;
37
38
  bindTimestamp(parameterIndex: number, value: DuckDBTimestampValue): void;
38
39
  bindTimestampTZ(parameterIndex: number, value: DuckDBTimestampTZValue): void;
40
+ bindTimestampSeconds(parameterIndex: number, value: DuckDBTimestampSecondsValue): void;
41
+ bindTimestampMilliseconds(parameterIndex: number, value: DuckDBTimestampMillisecondsValue): void;
42
+ bindTimestampNanoseconds(parameterIndex: number, value: DuckDBTimestampNanosecondsValue): void;
39
43
  bindInterval(parameterIndex: number, value: DuckDBIntervalValue): void;
40
44
  bindVarchar(parameterIndex: number, value: string): void;
41
45
  bindBlob(parameterIndex: number, value: Uint8Array): void;
46
+ bindEnum(parameterIndex: number, value: string, type: DuckDBEnumType): void;
42
47
  bindArray(parameterIndex: number, value: DuckDBArrayValue, type: DuckDBArrayType): void;
43
48
  bindList(parameterIndex: number, value: DuckDBListValue, type: DuckDBListType): void;
44
49
  bindStruct(parameterIndex: number, value: DuckDBStructValue, type: DuckDBStructType): void;
50
+ bindUUID(parameterIndex: number, value: DuckDBUUIDValue): void;
51
+ bindBit(parameterIndex: number, value: DuckDBBitValue): void;
45
52
  bindNull(parameterIndex: number): void;
46
53
  bindValue(parameterIndex: number, value: DuckDBValue, type: DuckDBType): void;
47
54
  bind(values: DuckDBValue[] | Record<string, DuckDBValue>, types?: DuckDBType[] | Record<string, DuckDBType | undefined>): void;
@@ -72,6 +72,9 @@ class DuckDBPreparedStatement {
72
72
  bindUHugeInt(parameterIndex, value) {
73
73
  node_bindings_1.default.bind_uhugeint(this.prepared_statement, parameterIndex, value);
74
74
  }
75
+ bindVarInt(parameterIndex, value) {
76
+ this.bindValue(parameterIndex, value, DuckDBType_1.VARINT);
77
+ }
75
78
  bindDecimal(parameterIndex, value) {
76
79
  node_bindings_1.default.bind_decimal(this.prepared_statement, parameterIndex, value);
77
80
  }
@@ -96,7 +99,15 @@ class DuckDBPreparedStatement {
96
99
  bindTimestampTZ(parameterIndex, value) {
97
100
  this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMPTZ);
98
101
  }
99
- // TODO: bind TIMESTAMPS_S/_MS/_NS
102
+ bindTimestampSeconds(parameterIndex, value) {
103
+ this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMP_S);
104
+ }
105
+ bindTimestampMilliseconds(parameterIndex, value) {
106
+ this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMP_MS);
107
+ }
108
+ bindTimestampNanoseconds(parameterIndex, value) {
109
+ this.bindValue(parameterIndex, value, DuckDBType_1.TIMESTAMP_NS);
110
+ }
100
111
  bindInterval(parameterIndex, value) {
101
112
  node_bindings_1.default.bind_interval(this.prepared_statement, parameterIndex, value);
102
113
  }
@@ -106,7 +117,9 @@ class DuckDBPreparedStatement {
106
117
  bindBlob(parameterIndex, value) {
107
118
  node_bindings_1.default.bind_blob(this.prepared_statement, parameterIndex, value);
108
119
  }
109
- // TODO: bind ENUM
120
+ bindEnum(parameterIndex, value, type) {
121
+ this.bindValue(parameterIndex, value, type);
122
+ }
110
123
  bindArray(parameterIndex, value, type) {
111
124
  this.bindValue(parameterIndex, value, type);
112
125
  }
@@ -117,8 +130,12 @@ class DuckDBPreparedStatement {
117
130
  this.bindValue(parameterIndex, value, type);
118
131
  }
119
132
  // TODO: bind MAP, UNION
120
- // TODO: bind UUID
121
- // TODO: bind BIT
133
+ bindUUID(parameterIndex, value) {
134
+ this.bindValue(parameterIndex, value, DuckDBType_1.UUID);
135
+ }
136
+ bindBit(parameterIndex, value) {
137
+ this.bindValue(parameterIndex, value, DuckDBType_1.BIT);
138
+ }
122
139
  bindNull(parameterIndex) {
123
140
  node_bindings_1.default.bind_null(this.prepared_statement, parameterIndex);
124
141
  }
@@ -74,7 +74,8 @@ function getVarIntFromBytes(bytes) {
74
74
  const positive = (firstByte & 0x80) > 0;
75
75
  const uint64Mask = positive ? 0n : 0xffffffffffffffffn;
76
76
  const uint8Mask = positive ? 0 : 0xff;
77
- const dv = new DataView(bytes.buffer, bytes.byteOffset + 3, bytes.byteLength - 3);
77
+ const dv = new DataView(// bytes is big endian
78
+ bytes.buffer, bytes.byteOffset + 3, bytes.byteLength - 3);
78
79
  const lastUint64Offset = dv.byteLength - 8;
79
80
  let offset = 0;
80
81
  let result = 0n;
@@ -89,26 +90,29 @@ function getVarIntFromBytes(bytes) {
89
90
  return positive ? result : -result;
90
91
  }
91
92
  function getBytesFromVarInt(varint) {
92
- const numberBytes = [];
93
+ const numberBytes = []; // little endian
94
+ const negative = varint < 0;
93
95
  if (varint === 0n) {
94
96
  numberBytes.push(0);
95
97
  }
96
98
  else {
97
- while (varint !== 0n) {
98
- numberBytes.push(Number(BigInt.asUintN(8, varint)));
99
- varint >>= 8n;
99
+ let vi = varint < 0 ? -varint : varint;
100
+ while (vi !== 0n) {
101
+ numberBytes.push(Number(BigInt.asUintN(8, vi)));
102
+ vi >>= 8n;
100
103
  }
101
104
  }
102
- const varIntBytes = new Uint8Array(3 + numberBytes.length);
105
+ const varIntBytes = new Uint8Array(3 + numberBytes.length); // big endian
103
106
  let header = 0x800000 | numberBytes.length;
104
- if (varint < 0) {
107
+ if (negative) {
105
108
  header = ~header;
106
109
  }
107
110
  varIntBytes[0] = 0xff & (header >> 16);
108
111
  varIntBytes[1] = 0xff & (header >> 8);
109
112
  varIntBytes[2] = 0xff & header;
110
113
  for (let i = 0; i < numberBytes.length; i++) {
111
- varIntBytes[3 + i] = numberBytes[i];
114
+ const byte = numberBytes[numberBytes.length - 1 - i];
115
+ varIntBytes[3 + i] = negative ? ~byte : byte;
112
116
  }
113
117
  return varIntBytes;
114
118
  }
@@ -2176,7 +2180,7 @@ class DuckDBUUIDVector extends DuckDBVector {
2176
2180
  }
2177
2181
  getItem(itemIndex) {
2178
2182
  return this.validity.itemValid(itemIndex)
2179
- ? new values_1.DuckDBUUIDValue(getInt128(this.dataView, itemIndex * 16))
2183
+ ? values_1.DuckDBUUIDValue.fromStoredHugeInt(getInt128(this.dataView, itemIndex * 16))
2180
2184
  : null;
2181
2185
  }
2182
2186
  setItem(itemIndex, value) {
@@ -8,7 +8,11 @@ const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
8
8
  const DuckDBTypeId_1 = require("./DuckDBTypeId");
9
9
  const values_1 = require("./values");
10
10
  function createValue(type, input) {
11
- switch (type.typeId) {
11
+ if (input === null) {
12
+ return node_bindings_1.default.create_null_value();
13
+ }
14
+ const { typeId } = type;
15
+ switch (typeId) {
12
16
  case DuckDBTypeId_1.DuckDBTypeId.BOOLEAN:
13
17
  if (typeof input === 'boolean') {
14
18
  return node_bindings_1.default.create_bool(input);
@@ -105,15 +109,30 @@ function createValue(type, input) {
105
109
  }
106
110
  throw new Error(`input is not a DuckDBBlobValue`);
107
111
  case DuckDBTypeId_1.DuckDBTypeId.DECIMAL:
108
- throw new Error(`not yet implemented for DECIMAL`); // TODO: implement when available in 1.2.0
112
+ if (input instanceof values_1.DuckDBDecimalValue) {
113
+ return node_bindings_1.default.create_decimal(input);
114
+ }
115
+ throw new Error(`input is not a DuckDBDecimalValue`);
109
116
  case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_S:
110
- throw new Error(`not yet implemented for TIMESTAMP_S`); // TODO: implement when available in 1.2.0
117
+ if (input instanceof values_1.DuckDBTimestampSecondsValue) {
118
+ return node_bindings_1.default.create_timestamp_s(input);
119
+ }
120
+ throw new Error(`input is not a DuckDBTimestampSecondsValue`);
111
121
  case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_MS:
112
- throw new Error(`not yet implemented for TIMESTAMP_MS`); // TODO: implement when available in 1.2.0
122
+ if (input instanceof values_1.DuckDBTimestampMillisecondsValue) {
123
+ return node_bindings_1.default.create_timestamp_ms(input);
124
+ }
125
+ throw new Error(`input is not a DuckDBTimestampMillisecondsValue`);
113
126
  case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_NS:
114
- throw new Error(`not yet implemented for TIMESTAMP_NS`); // TODO: implement when available in 1.2.0
127
+ if (input instanceof values_1.DuckDBTimestampNanosecondsValue) {
128
+ return node_bindings_1.default.create_timestamp_ns(input);
129
+ }
130
+ throw new Error(`input is not a DuckDBTimestampNanosecondsValue`);
115
131
  case DuckDBTypeId_1.DuckDBTypeId.ENUM:
116
- throw new Error(`not yet implemented for ENUM`); // TODO: implement when available in 1.2.0
132
+ if (typeof input === 'string') {
133
+ return node_bindings_1.default.create_enum_value(type.toLogicalType().logical_type, type.indexForValue(input));
134
+ }
135
+ throw new Error(`input is not a string`);
117
136
  case DuckDBTypeId_1.DuckDBTypeId.LIST:
118
137
  if (input instanceof values_1.DuckDBListValue) {
119
138
  if (type.valueType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY) {
@@ -124,7 +143,7 @@ function createValue(type, input) {
124
143
  throw new Error(`input is not a DuckDBListValue`);
125
144
  case DuckDBTypeId_1.DuckDBTypeId.STRUCT:
126
145
  if (input instanceof values_1.DuckDBStructValue) {
127
- if (type.entryTypes.find((type) => type.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY)) {
146
+ if (type.entryTypes.find((entryType) => entryType.typeId === DuckDBTypeId_1.DuckDBTypeId.ANY)) {
128
147
  throw new Error('Cannot create structs with an entry type of ANY. Specify a specific type.');
129
148
  }
130
149
  return node_bindings_1.default.create_struct_value(type.toLogicalType().logical_type, Object.values(input.entries).map((value, i) => createValue(type.entryTypes[i], value)));
@@ -141,11 +160,17 @@ function createValue(type, input) {
141
160
  }
142
161
  throw new Error(`input is not a DuckDBArrayValue`);
143
162
  case DuckDBTypeId_1.DuckDBTypeId.UUID:
144
- throw new Error(`not yet implemented for UUID`); // TODO: implement when available in 1.2.0
163
+ if (input instanceof values_1.DuckDBUUIDValue) {
164
+ return node_bindings_1.default.create_uuid(input.toUint128());
165
+ }
166
+ throw new Error(`input is not a bigint`);
145
167
  case DuckDBTypeId_1.DuckDBTypeId.UNION:
146
168
  throw new Error(`not yet implemented for UNION`); // TODO: implement when available, hopefully in 1.2.0
147
- case DuckDBTypeId_1.DuckDBTypeId.UNION:
148
- throw new Error(`not yet implemented for BIT`); // TODO: implement when available in 1.2.0
169
+ case DuckDBTypeId_1.DuckDBTypeId.BIT:
170
+ if (input instanceof values_1.DuckDBBitValue) {
171
+ return node_bindings_1.default.create_bit(input.data);
172
+ }
173
+ throw new Error(`input is not a DuckDBBitValue`);
149
174
  case DuckDBTypeId_1.DuckDBTypeId.TIME_TZ:
150
175
  if (input instanceof values_1.DuckDBTimeTZValue) {
151
176
  return node_bindings_1.default.create_time_tz_value(input);
@@ -153,16 +178,19 @@ function createValue(type, input) {
153
178
  throw new Error(`input is not a DuckDBTimeTZValue`);
154
179
  case DuckDBTypeId_1.DuckDBTypeId.TIMESTAMP_TZ:
155
180
  if (input instanceof values_1.DuckDBTimestampTZValue) {
156
- return node_bindings_1.default.create_timestamp(input); // TODO: change to create_timestamp_tz when available in 1.2.0
181
+ return node_bindings_1.default.create_timestamp_tz(input);
157
182
  }
158
183
  throw new Error(`input is not a DuckDBTimestampTZValue`);
159
184
  case DuckDBTypeId_1.DuckDBTypeId.ANY:
160
185
  throw new Error(`Cannot create values of type ANY. Specify a specific type.`);
161
186
  case DuckDBTypeId_1.DuckDBTypeId.VARINT:
162
- throw new Error(`not yet implemented for VARINT`); // TODO: implement when available in 1.2.0
187
+ if (typeof input === 'bigint') {
188
+ return node_bindings_1.default.create_varint(input);
189
+ }
190
+ throw new Error(`input is not a bigint`);
163
191
  case DuckDBTypeId_1.DuckDBTypeId.SQLNULL:
164
- throw new Error(`not yet implemented for SQLNUll`); // TODO: implement when available in 1.2.0
192
+ return node_bindings_1.default.create_null_value();
165
193
  default:
166
- throw new Error(`unrecognized type id ${type.typeId}`);
194
+ throw new Error(`unrecognized type id ${typeId}`);
167
195
  }
168
196
  }
@@ -1,8 +1,19 @@
1
1
  export declare class DuckDBUUIDValue {
2
2
  readonly hugeint: bigint;
3
- constructor(hugeint: bigint);
3
+ private constructor();
4
+ /** Return the UUID as an unsigned 128-bit integer in a JS BigInt. */
5
+ toUint128(): bigint;
4
6
  toString(): string;
7
+ /** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
8
+ static fromUint128(uint128: bigint): DuckDBUUIDValue;
9
+ /**
10
+ * Create a DuckDBUUIDValue from a HUGEINT as stored by DuckDB.
11
+ *
12
+ * UUID values are stored with their MSB flipped so their numeric ordering matches their string ordering.
13
+ */
14
+ static fromStoredHugeInt(hugeint: bigint): DuckDBUUIDValue;
5
15
  static readonly Max: DuckDBUUIDValue;
6
16
  static readonly Min: DuckDBUUIDValue;
7
17
  }
8
- export declare function uuidValue(hugeint: bigint): DuckDBUUIDValue;
18
+ /** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
19
+ export declare function uuidValue(uint128: bigint): DuckDBUUIDValue;
@@ -7,18 +7,34 @@ class DuckDBUUIDValue {
7
7
  constructor(hugeint) {
8
8
  this.hugeint = hugeint;
9
9
  }
10
- toString() {
10
+ /** Return the UUID as an unsigned 128-bit integer in a JS BigInt. */
11
+ toUint128() {
11
12
  // UUID values are stored with their MSB flipped so their numeric ordering matches their string ordering.
12
- const flipped = this.hugeint ^ 0x80000000000000000000000000000000n;
13
- // Truncate to 32 hex digits, then prepend with a hex 1, before converting to a hex string.
13
+ return (this.hugeint ^ 0x80000000000000000000000000000000n) & 0xffffffffffffffffffffffffffffffffn;
14
+ }
15
+ toString() {
16
+ // Prepend with a (hex) 1 before converting to a hex string.
14
17
  // This ensures the trailing 32 characters are the hex digits we want, left padded with zeros as needed.
15
- const hex = ((flipped & 0xffffffffffffffffffffffffffffffffn) | 0x100000000000000000000000000000000n).toString(16);
18
+ const hex = (this.toUint128() | 0x100000000000000000000000000000000n).toString(16);
16
19
  return `${hex.substring(1, 9)}-${hex.substring(9, 13)}-${hex.substring(13, 17)}-${hex.substring(17, 21)}-${hex.substring(21, 33)}`;
17
20
  }
21
+ /** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
22
+ static fromUint128(uint128) {
23
+ return new DuckDBUUIDValue((uint128 ^ 0x80000000000000000000000000000000n) & 0xffffffffffffffffffffffffffffffffn);
24
+ }
25
+ /**
26
+ * Create a DuckDBUUIDValue from a HUGEINT as stored by DuckDB.
27
+ *
28
+ * UUID values are stored with their MSB flipped so their numeric ordering matches their string ordering.
29
+ */
30
+ static fromStoredHugeInt(hugeint) {
31
+ return new DuckDBUUIDValue(hugeint);
32
+ }
18
33
  static Max = new DuckDBUUIDValue(2n ** 127n - 1n); // 7fffffffffffffffffffffffffffffff
19
34
  static Min = new DuckDBUUIDValue(-(2n ** 127n)); // 80000000000000000000000000000000
20
35
  }
21
36
  exports.DuckDBUUIDValue = DuckDBUUIDValue;
22
- function uuidValue(hugeint) {
23
- return new DuckDBUUIDValue(hugeint);
37
+ /** Create a DuckDBUUIDValue from an unsigned 128-bit integer in a JS BigInt. */
38
+ function uuidValue(uint128) {
39
+ return DuckDBUUIDValue.fromUint128(uint128);
24
40
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@duckdb/node-api",
3
- "version": "1.2.0-alpha.14",
3
+ "version": "1.2.0-alpha.15",
4
4
  "license": "MIT",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "dependencies": {
8
- "@duckdb/node-bindings": "1.2.0-alpha.14"
8
+ "@duckdb/node-bindings": "1.2.0-alpha.15"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",