@leonardovida-md/drizzle-neo-duckdb 1.1.0 → 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.
@@ -32,7 +32,7 @@ function toDecoderInput<TDecoder extends DriverValueDecoder<unknown, unknown>>(
32
32
  return value as DecoderInput<TDecoder>;
33
33
  }
34
34
 
35
- function normalizeInet(value: unknown): unknown {
35
+ export function normalizeInet(value: unknown): unknown {
36
36
  if (
37
37
  value &&
38
38
  typeof value === 'object' &&
@@ -70,7 +70,7 @@ function normalizeInet(value: unknown): unknown {
70
70
  return value;
71
71
  }
72
72
 
73
- function normalizeTimestampString(
73
+ export function normalizeTimestampString(
74
74
  value: unknown,
75
75
  withTimezone: boolean
76
76
  ): string | unknown {
@@ -88,7 +88,7 @@ function normalizeTimestampString(
88
88
  return value;
89
89
  }
90
90
 
91
- function normalizeTimestamp(
91
+ export function normalizeTimestamp(
92
92
  value: unknown,
93
93
  withTimezone: boolean
94
94
  ): Date | unknown {
@@ -105,7 +105,7 @@ function normalizeTimestamp(
105
105
  return value;
106
106
  }
107
107
 
108
- function normalizeDateString(value: unknown): string | unknown {
108
+ export function normalizeDateString(value: unknown): string | unknown {
109
109
  if (value instanceof Date) {
110
110
  return value.toISOString().slice(0, 10);
111
111
  }
@@ -115,7 +115,7 @@ function normalizeDateString(value: unknown): string | unknown {
115
115
  return value;
116
116
  }
117
117
 
118
- function normalizeDateValue(value: unknown): Date | unknown {
118
+ export function normalizeDateValue(value: unknown): Date | unknown {
119
119
  if (value instanceof Date) {
120
120
  return value;
121
121
  }
@@ -125,7 +125,7 @@ function normalizeDateValue(value: unknown): Date | unknown {
125
125
  return value;
126
126
  }
127
127
 
128
- function normalizeTime(value: unknown): string | unknown {
128
+ export function normalizeTime(value: unknown): string | unknown {
129
129
  if (typeof value === 'bigint') {
130
130
  const totalMillis = Number(value) / 1000;
131
131
  const date = new Date(totalMillis);
@@ -137,7 +137,7 @@ function normalizeTime(value: unknown): string | unknown {
137
137
  return value;
138
138
  }
139
139
 
140
- function normalizeInterval(value: unknown): string | unknown {
140
+ export function normalizeInterval(value: unknown): string | unknown {
141
141
  if (
142
142
  value &&
143
143
  typeof value === 'object' &&
@@ -45,7 +45,7 @@ export interface MapValueWrapper
45
45
  }
46
46
 
47
47
  export interface TimestampValueWrapper
48
- extends DuckDBValueWrapper<'timestamp', Date | string> {
48
+ extends DuckDBValueWrapper<'timestamp', Date | string | number | bigint> {
49
49
  readonly withTimezone: boolean;
50
50
  readonly precision?: number;
51
51
  }
@@ -126,7 +126,7 @@ export function wrapMap(
126
126
  }
127
127
 
128
128
  export function wrapTimestamp(
129
- data: Date | string,
129
+ data: Date | string | number | bigint,
130
130
  withTimezone: boolean,
131
131
  precision?: number
132
132
  ): TimestampValueWrapper {
@@ -32,14 +32,24 @@ import {
32
32
  } from './value-wrappers-core.ts';
33
33
 
34
34
  /**
35
- * Convert a Date or string to microseconds since Unix epoch.
36
- * Handles both Date objects and ISO-like timestamp strings.
35
+ * Convert a Date/string/epoch number to microseconds since Unix epoch.
36
+ * Handles Date objects, ISO-like strings, bigint, and millisecond numbers.
37
37
  */
38
- function dateToMicros(value: Date | string): bigint {
38
+ function dateToMicros(value: Date | string | number | bigint): bigint {
39
39
  if (value instanceof Date) {
40
40
  return BigInt(value.getTime()) * 1000n;
41
41
  }
42
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
+
43
53
  // For strings, normalize the format for reliable parsing
44
54
  // Handle both 'YYYY-MM-DD HH:MM:SS' and 'YYYY-MM-DDTHH:MM:SS' formats
45
55
  let normalized = value;