Skip to content

Support Temporal values in escape() #43

Description

@pdeveltere

Temporal is the modern replacement for Date and is now shipping in runtimes (Node 26, etc.). Passing a Temporal value to escape() today falls through to the generic object handling and produces broken SQL:

escape(Temporal.Instant.from('2012-05-07T11:42:03.002Z'));
// currently => garbage / object expansion, not a valid literal

Date is already special-cased; Temporal deserves the same treatment.

Proposed API

Mirror the existing Date behavior, mapping each Temporal type to its natural MySQL literal:

Temporal type Treated as Output
Instant, ZonedDateTime absolute time dateToString, honoring the timezone arg exactly like Date (ms precision)
PlainDateTime wall-clock DATETIME literal, timezone ignored
PlainDate wall-clock DATE literal
PlainTime wall-clock TIME literal
others (Duration, PlainYearMonth, ...) ISO-string fallback

Detection via Object.prototype.toString (Symbol.toStringTag, i.e. [object Temporal.*]), so the Temporal global is never referenced and runtimes without Temporal are unaffected.

Open questions for maintainers

  1. PrecisionInstant via epochMilliseconds gives millisecond precision (identical to Date). Should sub-ms (µs/ns) be preserved for DATETIME(6), or is matching Date preferred?
  2. SqlValue typing — upgrade to TS 6.0.3 to support the esnext.temporal lib? https://www.typescriptlang.org/docs/handbook/release-notes/typescript-6-0.html#new-types-for-temporal
  3. Type coverage — include only the 5 date/time-mapped types in the SqlValue union, or all Temporal types?

Reference

Opened #42 as a concrete starting point (structural-typing variant). Happy to adjust the API based on the discussion here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions