@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/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
@@ -7,3 +7,4 @@ export * from './client.ts';
7
7
  export * from './pool.ts';
8
8
  export * from './olap.ts';
9
9
  export * from './value-wrappers.ts';
10
+ export * from './options.ts';