@leonardovida-md/drizzle-neo-duckdb 1.1.1 → 1.1.3
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 +3 -2
- package/dist/driver.d.ts +7 -3
- package/dist/duckdb-introspect.mjs +595 -50
- package/dist/helpers.mjs +31 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +621 -50
- package/dist/options.d.ts +10 -0
- package/dist/session.d.ts +11 -5
- package/dist/sql/query-rewriters.d.ts +12 -0
- package/package.json +1 -1
- package/src/client.ts +300 -40
- package/src/columns.ts +51 -4
- package/src/driver.ts +30 -5
- package/src/index.ts +1 -0
- package/src/options.ts +40 -0
- package/src/session.ts +128 -27
- package/src/sql/query-rewriters.ts +503 -0
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,
|
|
@@ -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