Skip to content

feat: add Temporal support to escape#42

Merged
wellwelwel merged 5 commits into
mysqljs:mainfrom
pdeveltere:feat/temporal-escape
Jul 12, 2026
Merged

feat: add Temporal support to escape#42
wellwelwel merged 5 commits into
mysqljs:mainfrom
pdeveltere:feat/temporal-escape

Conversation

@pdeveltere

@pdeveltere pdeveltere commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

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

Behavior

  • 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 (Duration, PlainYearMonth, PlainMonthDay) fall back to their ISO string.

Notes

  • With chore: update TypeScript to 6.0.3 #44 merged, Temporal values are typed natively via the esnext.temporal lib: the new TemporalValue union (part of SqlValue) covers all eight Temporal types.
  • Runtime detection stays Symbol.toStringTag-based (Object.prototype.toString), so the Temporal global is never referenced and polyfilled values work too.
  • Tests run on every runtime: they use the native Temporal global when present and fall back to @js-temporal/polyfill (dev-only dependency) otherwise — CI's lts/* Node has no Temporal global yet, so without the fallback the suite would silently skip (this is what previously showed up as low patch coverage).
  • Includes tests for all branches (absolute, wall-clock, ISO fallback) and README docs.

Escaping a Temporal value (e.g. Temporal.Instant) currently falls through to
the generic object handling 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 (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 no Temporal lib types are needed;
the new TemporalLike type is declared structurally. Adds tests (skipped when
Temporal is unavailable) and README docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread test/temporal.test.ts Outdated
@wellwelwel wellwelwel changed the title Add Temporal support to escape feat: add Temporal support to escape Jul 12, 2026
@wellwelwel wellwelwel linked an issue Jul 12, 2026 that may be closed by this pull request
@codecov-commenter

codecov-commenter commented Jul 12, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (58a69f1) to head (b82ca06).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #42   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          548       561   +13     
=========================================
+ Hits           548       561   +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wellwelwel wellwelwel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @pdeveltere! I've noted a few points to review. Feel free to reach out if you need any help 🙋🏻‍♂️

Comment thread src/index.ts
Comment thread src/index.ts Outdated
Comment thread test/temporal.test.ts Outdated
- type Temporal values via the esnext.temporal lib (unblocked by mysqljs#44)
  instead of the structural TemporalLike shape
- add tests for the ISO-string fallback (Duration, PlainYearMonth,
  PlainMonthDay)
- run Temporal tests on every runtime via @js-temporal/polyfill (dev-only)
  so coverage no longer depends on the CI Node version
- trim comments to decision notes per review
@pdeveltere

pdeveltere commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@wellwelwel thanks for the quick review! I think I've attended all the points, let me know if something is missing still.

@wellwelwel wellwelwel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, @pdeveltere!

@wellwelwel
wellwelwel merged commit 5ea3a69 into mysqljs:main Jul 12, 2026
11 checks passed
@pdeveltere
pdeveltere deleted the feat/temporal-escape branch July 12, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Temporal values in escape()

3 participants