Skip to content

Add Temporal support to SqlString.escape - #74

Open
pdeveltere wants to merge 1 commit into
mysqljs:masterfrom
pdeveltere:feat/temporal-escape
Open

Add Temporal support to SqlString.escape#74
pdeveltere wants to merge 1 commit into
mysqljs:masterfrom
pdeveltere:feat/temporal-escape

Conversation

@pdeveltere

Copy link
Copy Markdown

Escaping a Temporal value (e.g. Temporal.Instant) currently falls through to objectToValues and produces broken SQL. This teaches escape() about Temporal, mirroring the existing Date handling.

  • Instant / ZonedDateTime: absolute times, delegated to dateToString so the timeZone argument behaves exactly as it does for Date (millisecond precision).
  • PlainDateTime / PlainDate / PlainTime: wall-clock values, emitted verbatim as DATETIME / DATE / TIME literals (timeZone ignored).
  • Other Temporal types fall back to their ISO string.

Temporal types are detected via Object.prototype.toString (Symbol.toStringTag), so the Temporal global is never referenced and the node >= 0.6 engines range is unaffected — the branch simply never fires on runtimes without Temporal.

Adds tests (skipped when Temporal is unavailable) and README docs. npm test and eslint . both pass.

Escaping a Temporal value (e.g. Temporal.Instant) currently falls through
to objectToValues and produces broken SQL. Teach escape() about Temporal,
mirroring the existing Date handling.
- Instant / ZonedDateTime: absolute times, delegated to dateToString so the
timeZone argument behaves exactly as it does for Date (ms precision).
- PlainDateTime / PlainDate / PlainTime: wall-clock values, emitted verbatim
as DATETIME / DATE / TIME literals (timeZone ignored).
- Other Temporal types fall back to their ISO string.
Temporal types are detected via Object.prototype.toString (Symbol.toStringTag),
so the Temporal global is never referenced and the `node >= 0.6` engines range
is unaffected. Adds tests (skipped when Temporal is unavailable) and README docs.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@pdeveltere