@leonardovida-md/drizzle-neo-duckdb 1.0.3 → 1.1.1
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 +20 -5
- package/dist/client.d.ts +7 -1
- package/dist/columns.d.ts +6 -1
- package/dist/dialect.d.ts +21 -0
- package/dist/driver.d.ts +33 -1
- package/dist/duckdb-introspect.mjs +610 -114
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.mjs +319 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +603 -117
- package/dist/introspect.d.ts +9 -0
- package/dist/pool.d.ts +30 -0
- package/dist/session.d.ts +7 -1
- package/dist/sql/query-rewriters.d.ts +1 -1
- package/dist/sql/result-mapper.d.ts +7 -0
- package/dist/utils.d.ts +1 -1
- package/dist/value-wrappers-core.d.ts +42 -0
- package/dist/value-wrappers.d.ts +2 -98
- package/package.json +6 -2
- package/src/bin/duckdb-introspect.ts +27 -0
- package/src/client.ts +54 -13
- package/src/columns.ts +10 -10
- package/src/dialect.ts +51 -3
- package/src/driver.ts +204 -7
- package/src/helpers.ts +18 -0
- package/src/index.ts +1 -0
- package/src/introspect.ts +47 -29
- package/src/migrator.ts +1 -1
- package/src/olap.ts +1 -0
- package/src/pool.ts +274 -0
- package/src/session.ts +134 -15
- package/src/sql/query-rewriters.ts +177 -116
- package/src/sql/result-mapper.ts +7 -7
- package/src/utils.ts +1 -1
- package/src/value-wrappers-core.ts +156 -0
- package/src/value-wrappers.ts +60 -219
package/src/value-wrappers.ts
CHANGED
|
@@ -9,229 +9,47 @@ import {
|
|
|
9
9
|
type DuckDBValue,
|
|
10
10
|
type DuckDBMapEntry,
|
|
11
11
|
} from '@duckdb/node-api';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
readonly kind: TKind;
|
|
40
|
-
readonly data: TData;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* List wrapper - maps to DuckDBListValue
|
|
45
|
-
*/
|
|
46
|
-
export interface ListValueWrapper
|
|
47
|
-
extends DuckDBValueWrapper<'list', unknown[]> {
|
|
48
|
-
readonly elementType?: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Array wrapper (fixed size) - maps to DuckDBArrayValue
|
|
53
|
-
*/
|
|
54
|
-
export interface ArrayValueWrapper
|
|
55
|
-
extends DuckDBValueWrapper<'array', unknown[]> {
|
|
56
|
-
readonly elementType?: string;
|
|
57
|
-
readonly fixedLength?: number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Struct wrapper - maps to DuckDBStructValue
|
|
62
|
-
*/
|
|
63
|
-
export interface StructValueWrapper
|
|
64
|
-
extends DuckDBValueWrapper<'struct', Record<string, unknown>> {
|
|
65
|
-
readonly schema?: Record<string, string>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Map wrapper - maps to DuckDBMapValue
|
|
70
|
-
*/
|
|
71
|
-
export interface MapValueWrapper
|
|
72
|
-
extends DuckDBValueWrapper<'map', Record<string, unknown>> {
|
|
73
|
-
readonly valueType?: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Timestamp wrapper - maps to DuckDBTimestampValue or DuckDBTimestampTZValue
|
|
78
|
-
*/
|
|
79
|
-
export interface TimestampValueWrapper
|
|
80
|
-
extends DuckDBValueWrapper<'timestamp', Date | string> {
|
|
81
|
-
readonly withTimezone: boolean;
|
|
82
|
-
readonly precision?: number;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Blob wrapper - maps to DuckDBBlobValue
|
|
87
|
-
*/
|
|
88
|
-
export interface BlobValueWrapper
|
|
89
|
-
extends DuckDBValueWrapper<'blob', Buffer | Uint8Array> {}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* JSON wrapper - delays JSON.stringify() to binding time.
|
|
93
|
-
* DuckDB stores JSON as VARCHAR internally.
|
|
94
|
-
*/
|
|
95
|
-
export interface JsonValueWrapper extends DuckDBValueWrapper<'json', unknown> {}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Union of all wrapper types for exhaustive type checking.
|
|
99
|
-
*/
|
|
100
|
-
export type AnyDuckDBValueWrapper =
|
|
101
|
-
| ListValueWrapper
|
|
102
|
-
| ArrayValueWrapper
|
|
103
|
-
| StructValueWrapper
|
|
104
|
-
| MapValueWrapper
|
|
105
|
-
| TimestampValueWrapper
|
|
106
|
-
| BlobValueWrapper
|
|
107
|
-
| JsonValueWrapper;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Type guard to check if a value is a tagged DuckDB wrapper.
|
|
111
|
-
* Optimized for fast detection in the hot path.
|
|
112
|
-
*/
|
|
113
|
-
export function isDuckDBWrapper(
|
|
114
|
-
value: unknown
|
|
115
|
-
): value is AnyDuckDBValueWrapper {
|
|
116
|
-
return (
|
|
117
|
-
value !== null &&
|
|
118
|
-
typeof value === 'object' &&
|
|
119
|
-
DUCKDB_VALUE_MARKER in value &&
|
|
120
|
-
(value as DuckDBValueWrapper)[DUCKDB_VALUE_MARKER] === true
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Create a list wrapper for variable-length lists.
|
|
126
|
-
*/
|
|
127
|
-
export function wrapList(
|
|
128
|
-
data: unknown[],
|
|
129
|
-
elementType?: string
|
|
130
|
-
): ListValueWrapper {
|
|
131
|
-
return {
|
|
132
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
133
|
-
kind: 'list',
|
|
134
|
-
data,
|
|
135
|
-
elementType,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Create an array wrapper for fixed-length arrays.
|
|
141
|
-
*/
|
|
142
|
-
export function wrapArray(
|
|
143
|
-
data: unknown[],
|
|
144
|
-
elementType?: string,
|
|
145
|
-
fixedLength?: number
|
|
146
|
-
): ArrayValueWrapper {
|
|
147
|
-
return {
|
|
148
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
149
|
-
kind: 'array',
|
|
150
|
-
data,
|
|
151
|
-
elementType,
|
|
152
|
-
fixedLength,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Create a struct wrapper for named field structures.
|
|
158
|
-
*/
|
|
159
|
-
export function wrapStruct(
|
|
160
|
-
data: Record<string, unknown>,
|
|
161
|
-
schema?: Record<string, string>
|
|
162
|
-
): StructValueWrapper {
|
|
163
|
-
return {
|
|
164
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
165
|
-
kind: 'struct',
|
|
166
|
-
data,
|
|
167
|
-
schema,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Create a map wrapper for key-value maps.
|
|
173
|
-
*/
|
|
174
|
-
export function wrapMap(
|
|
175
|
-
data: Record<string, unknown>,
|
|
176
|
-
valueType?: string
|
|
177
|
-
): MapValueWrapper {
|
|
178
|
-
return {
|
|
179
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
180
|
-
kind: 'map',
|
|
181
|
-
data,
|
|
182
|
-
valueType,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Create a timestamp wrapper.
|
|
188
|
-
*/
|
|
189
|
-
export function wrapTimestamp(
|
|
190
|
-
data: Date | string,
|
|
191
|
-
withTimezone: boolean,
|
|
192
|
-
precision?: number
|
|
193
|
-
): TimestampValueWrapper {
|
|
194
|
-
return {
|
|
195
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
196
|
-
kind: 'timestamp',
|
|
197
|
-
data,
|
|
198
|
-
withTimezone,
|
|
199
|
-
precision,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Create a blob wrapper for binary data.
|
|
205
|
-
*/
|
|
206
|
-
export function wrapBlob(data: Buffer | Uint8Array): BlobValueWrapper {
|
|
207
|
-
return {
|
|
208
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
209
|
-
kind: 'blob',
|
|
210
|
-
data,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Create a JSON wrapper that delays JSON.stringify() to binding time.
|
|
216
|
-
* This ensures consistent handling with other wrapped types.
|
|
217
|
-
*/
|
|
218
|
-
export function wrapJson(data: unknown): JsonValueWrapper {
|
|
219
|
-
return {
|
|
220
|
-
[DUCKDB_VALUE_MARKER]: true,
|
|
221
|
-
kind: 'json',
|
|
222
|
-
data,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Convert a Date or string to microseconds since Unix epoch.
|
|
228
|
-
* Handles both Date objects and ISO-like timestamp strings.
|
|
229
|
-
*/
|
|
230
|
-
function dateToMicros(value: Date | string): bigint {
|
|
12
|
+
import {
|
|
13
|
+
DUCKDB_VALUE_MARKER,
|
|
14
|
+
isDuckDBWrapper,
|
|
15
|
+
wrapArray,
|
|
16
|
+
wrapBlob,
|
|
17
|
+
wrapJson,
|
|
18
|
+
wrapList,
|
|
19
|
+
wrapMap,
|
|
20
|
+
wrapStruct,
|
|
21
|
+
wrapTimestamp,
|
|
22
|
+
type AnyDuckDBValueWrapper,
|
|
23
|
+
type DuckDBValueWrapper,
|
|
24
|
+
type ArrayValueWrapper,
|
|
25
|
+
type BlobValueWrapper,
|
|
26
|
+
type JsonValueWrapper,
|
|
27
|
+
type ListValueWrapper,
|
|
28
|
+
type MapValueWrapper,
|
|
29
|
+
type StructValueWrapper,
|
|
30
|
+
type TimestampValueWrapper,
|
|
31
|
+
type DuckDBValueKind,
|
|
32
|
+
} from './value-wrappers-core.ts';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Convert a Date/string/epoch number to microseconds since Unix epoch.
|
|
36
|
+
* Handles Date objects, ISO-like strings, bigint, and millisecond numbers.
|
|
37
|
+
*/
|
|
38
|
+
function dateToMicros(value: Date | string | number | bigint): bigint {
|
|
231
39
|
if (value instanceof Date) {
|
|
232
40
|
return BigInt(value.getTime()) * 1000n;
|
|
233
41
|
}
|
|
234
42
|
|
|
43
|
+
if (typeof value === 'bigint') {
|
|
44
|
+
// Assume bigint already in microseconds (DuckDB default)
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
// Assume JS milliseconds
|
|
50
|
+
return BigInt(Math.trunc(value)) * 1000n;
|
|
51
|
+
}
|
|
52
|
+
|
|
235
53
|
// For strings, normalize the format for reliable parsing
|
|
236
54
|
// Handle both 'YYYY-MM-DD HH:MM:SS' and 'YYYY-MM-DDTHH:MM:SS' formats
|
|
237
55
|
let normalized = value;
|
|
@@ -322,3 +140,26 @@ export function wrapperToNodeApiValue(
|
|
|
322
140
|
}
|
|
323
141
|
}
|
|
324
142
|
}
|
|
143
|
+
|
|
144
|
+
// Re-export core helpers for convenience and backward compatibility.
|
|
145
|
+
export {
|
|
146
|
+
DUCKDB_VALUE_MARKER,
|
|
147
|
+
isDuckDBWrapper,
|
|
148
|
+
wrapArray,
|
|
149
|
+
wrapBlob,
|
|
150
|
+
wrapJson,
|
|
151
|
+
wrapList,
|
|
152
|
+
wrapMap,
|
|
153
|
+
wrapStruct,
|
|
154
|
+
wrapTimestamp,
|
|
155
|
+
type AnyDuckDBValueWrapper,
|
|
156
|
+
type DuckDBValueWrapper,
|
|
157
|
+
type ArrayValueWrapper,
|
|
158
|
+
type BlobValueWrapper,
|
|
159
|
+
type JsonValueWrapper,
|
|
160
|
+
type ListValueWrapper,
|
|
161
|
+
type MapValueWrapper,
|
|
162
|
+
type StructValueWrapper,
|
|
163
|
+
type TimestampValueWrapper,
|
|
164
|
+
type DuckDBValueKind,
|
|
165
|
+
} from './value-wrappers-core.ts';
|