jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
444 stars 63 forks source link

Support native JavaScript Date type #28

Closed jeremydaly closed 4 years ago

jeremydaly commented 4 years ago

An original implementation of this was supplied in #20, but it needs some more thought.

Handling date input should be straightforward. If a native JavaScript Date object is passed as a parameter, we could automatically cast it to a stringValue (assuming MySQL and Postgres could handle it).

Parsing it back into a Date object might be a little more tricky. First, this would need to be optional. So we would likely add another config parameter like parseDates. This could be passed on instantiation or as a query configuration parameter (like database) and override the global setting. Second, we'd need to inspect the columnMetaData and whitelist data types that can be coerced.

Looking for feedback on this feature.

lucas-subli commented 4 years ago

+1

rodeyseijkens commented 4 years ago

+1

cklam2 commented 4 years ago

@jeremydaly we needed datetime support in our project so I implemented an initial version. See here for the changes: https://github.com/cklam2/data-api-client/tree/aws-timestamp-support

Changes in a nutshell:

Note that the readme is not yet updated. Can do that once we agree upon the implementation. And probably will also add additional unit tests for the date conversion methods.

Any feedback would be appreciated.

1 AWS services run in UTC time zone so in AWS the flag does nothing special. However when running in serverless offline mode (or when code is not running on AWS) the datetime value follows the server's time zone. For ppl who want to ensure that value is always stored as UTC (like in our case), they can use this option.

jeremydaly commented 4 years ago

Thanks for this, @cklam2! I'm working on wrapping up a major new version to another project, then I'll turn my attention back here.

coyoteecd commented 4 years ago

@jeremydaly it's July... can you merge and publish this?