@leonardovida-md/drizzle-neo-duckdb 1.1.0 → 1.1.2
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 +44 -85
- package/dist/client.d.ts +15 -1
- package/dist/columns.d.ts +8 -2
- package/dist/dialect.d.ts +21 -0
- package/dist/driver.d.ts +7 -3
- package/dist/duckdb-introspect.mjs +667 -133
- package/dist/helpers.mjs +35 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +695 -137
- package/dist/introspect.d.ts +8 -0
- package/dist/options.d.ts +10 -0
- package/dist/pool.d.ts +8 -0
- package/dist/session.d.ts +18 -6
- package/dist/sql/query-rewriters.d.ts +1 -0
- package/dist/sql/result-mapper.d.ts +7 -0
- package/dist/value-wrappers-core.d.ts +2 -2
- package/package.json +1 -1
- package/src/bin/duckdb-introspect.ts +27 -0
- package/src/client.ts +301 -38
- package/src/columns.ts +60 -13
- package/src/dialect.ts +51 -3
- package/src/driver.ts +45 -7
- package/src/index.ts +1 -0
- package/src/introspect.ts +23 -6
- package/src/options.ts +40 -0
- package/src/pool.ts +182 -12
- package/src/session.ts +206 -31
- package/src/sql/query-rewriters.ts +191 -75
- package/src/sql/result-mapper.ts +7 -7
- package/src/value-wrappers-core.ts +2 -2
- package/src/value-wrappers.ts +13 -3
package/dist/helpers.mjs
CHANGED
|
@@ -29,6 +29,15 @@ function wrapMap(data, valueType) {
|
|
|
29
29
|
valueType
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
function wrapTimestamp(data, withTimezone, precision) {
|
|
33
|
+
return {
|
|
34
|
+
[DUCKDB_VALUE_MARKER]: true,
|
|
35
|
+
kind: "timestamp",
|
|
36
|
+
data,
|
|
37
|
+
withTimezone,
|
|
38
|
+
precision
|
|
39
|
+
};
|
|
40
|
+
}
|
|
32
41
|
function wrapBlob(data) {
|
|
33
42
|
return {
|
|
34
43
|
[DUCKDB_VALUE_MARKER]: true,
|
|
@@ -119,11 +128,11 @@ var duckDbList = (name, elementType) => customType({
|
|
|
119
128
|
}
|
|
120
129
|
if (typeof value === "string") {
|
|
121
130
|
const parsed = coerceArrayString(value);
|
|
122
|
-
if (parsed) {
|
|
131
|
+
if (parsed !== undefined) {
|
|
123
132
|
return parsed;
|
|
124
133
|
}
|
|
125
134
|
}
|
|
126
|
-
return
|
|
135
|
+
return value;
|
|
127
136
|
}
|
|
128
137
|
})(name);
|
|
129
138
|
var duckDbArray = (name, elementType, fixedLength) => customType({
|
|
@@ -139,11 +148,11 @@ var duckDbArray = (name, elementType, fixedLength) => customType({
|
|
|
139
148
|
}
|
|
140
149
|
if (typeof value === "string") {
|
|
141
150
|
const parsed = coerceArrayString(value);
|
|
142
|
-
if (parsed) {
|
|
151
|
+
if (parsed !== undefined) {
|
|
143
152
|
return parsed;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
return
|
|
155
|
+
return value;
|
|
147
156
|
}
|
|
148
157
|
})(name);
|
|
149
158
|
var duckDbMap = (name, valueType) => customType({
|
|
@@ -228,6 +237,21 @@ var duckDbInterval = (name) => customType({
|
|
|
228
237
|
return value;
|
|
229
238
|
}
|
|
230
239
|
})(name);
|
|
240
|
+
function shouldBindTimestamp(options) {
|
|
241
|
+
const bindMode = options.bindMode ?? "auto";
|
|
242
|
+
if (bindMode === "bind")
|
|
243
|
+
return true;
|
|
244
|
+
if (bindMode === "literal")
|
|
245
|
+
return false;
|
|
246
|
+
const isBun = typeof process !== "undefined" && typeof process.versions?.bun !== "undefined";
|
|
247
|
+
if (isBun)
|
|
248
|
+
return false;
|
|
249
|
+
const forceLiteral = typeof process !== "undefined" ? process.env.DRIZZLE_DUCKDB_FORCE_LITERAL_TIMESTAMPS : undefined;
|
|
250
|
+
if (forceLiteral && forceLiteral !== "0") {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
231
255
|
var duckDbTimestamp = (name, options = {}) => customType({
|
|
232
256
|
dataType() {
|
|
233
257
|
if (options.withTimezone) {
|
|
@@ -237,12 +261,19 @@ var duckDbTimestamp = (name, options = {}) => customType({
|
|
|
237
261
|
return `TIMESTAMP${precision}`;
|
|
238
262
|
},
|
|
239
263
|
toDriver(value) {
|
|
264
|
+
if (shouldBindTimestamp(options)) {
|
|
265
|
+
return wrapTimestamp(value, options.withTimezone ?? false, options.precision);
|
|
266
|
+
}
|
|
240
267
|
const iso = value instanceof Date ? value.toISOString() : value;
|
|
241
268
|
const normalized = iso.replace("T", " ").replace("Z", "+00");
|
|
242
269
|
const typeKeyword = options.withTimezone ? "TIMESTAMPTZ" : "TIMESTAMP";
|
|
243
270
|
return sql.raw(`${typeKeyword} '${normalized}'`);
|
|
244
271
|
},
|
|
245
272
|
fromDriver(value) {
|
|
273
|
+
if (value && typeof value === "object" && "kind" in value && value.kind === "timestamp") {
|
|
274
|
+
const wrapped = value;
|
|
275
|
+
return wrapped.data instanceof Date ? wrapped.data : typeof wrapped.data === "number" || typeof wrapped.data === "bigint" ? new Date(Number(wrapped.data) / 1000) : wrapped.data;
|
|
276
|
+
}
|
|
246
277
|
if (options.mode === "string") {
|
|
247
278
|
if (value instanceof Date) {
|
|
248
279
|
return value.toISOString().replace("T", " ").replace("Z", "+00");
|
package/dist/index.d.ts
CHANGED