porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.03k stars 255 forks source link

Support Temporal.Instant for Timestamp columns #856

Closed zadeviggers closed 1 month ago

zadeviggers commented 2 months ago

The Temporal API is now available in Deno. Given this library's popularity in the Deno ecosystem, I think it would make sense to support passing Temporal.Instant objects the same way we can currently pass Date objects.

You can easily convert a Temporal.Instant to a Date like so:

// From the Temporal cookbook: https://tc39.es/proposal-temporal/docs/instant.html#interoperability-with-date
instant = Temporal.Instant.from('2020-01-01T00:00:00.123456789+05:30');
                                                           // => 2019-12-31T18:30:00.123456789Z
date = new Date(instant.epochMilliseconds);

Supporting the more advanced Temporal types, like Temporal.ZonedDateTime for Timestamptzs or Temporal.Duration for Intervals, could also be an interesting thing to pursue in the future.

langpavel commented 2 months ago

Note that you must run deno --unstable-temporal

porsager commented 1 month ago

Should be fairly trivial with a custom type? https://github.com/porsager/postgres?tab=readme-ov-file#custom-types