Skip to content

Commit 3dc2a5b

Browse files
Copilotbcho
andcommitted
Add documentation for datetime encoding/decoding formats
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
1 parent 4f6ef58 commit 3dc2a5b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

sdks/typescript/src/sqlite-connection.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ function decodeColumnValue<V = any>(args: {
229229
}
230230

231231
if (columnTypeName === "datetime") {
232+
// SQLite stores datetimes as strings but may return them in different formats
233+
// depending on how they were inserted. Support both ISO strings (from
234+
// Temporal.Instant.toString() or Date.toISOString()) and epoch milliseconds
235+
// (from numeric timestamps).
232236
if (typeof value === "string") {
233-
// Handle ISO string format
237+
// Handle ISO string format (e.g., "2024-01-01T00:00:00Z")
234238
return Temporal.Instant.from(value) as V;
235239
}
236240
if (typeof value === "number") {
@@ -247,12 +251,14 @@ function decodeColumnValue<V = any>(args: {
247251
}
248252

249253
function encodeColumnValue(value: any): any {
254+
// Encode Temporal types to ISO string format for SQLite storage
250255
if (value instanceof Temporal.Instant) {
251256
return value.toString();
252257
}
253258
if (value instanceof Temporal.Duration) {
254259
return value.toString();
255260
}
261+
// Legacy support for Date objects
256262
if (value instanceof Date) {
257263
return value.toISOString();
258264
}

0 commit comments

Comments
 (0)