@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/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
@@ -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';