Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interval type for Selectable is wrong (is string, should be PostgresInterval) #152

Open
felixfbecker opened this issue May 6, 2023 · 0 comments

Comments

@felixfbecker
Copy link

When using Selectable, the columns are not coerced into jsonb like in JSONSelectable, but parsed to whatever parsers registered with pg.

Selectable is wrong with some default parsers registed by pg. It correctly types timestamptz as Date according to the default date parser, but interval for example is parsed as a PostgresInterval object, but in Selectable it is typed as string. See https://github.com/brianc/node-pg-types/blob/v2.2.0/lib/textParsers.js#L199 and https://github.com/bendrucker/postgres-interval/blob/v1.2.0/index.d.ts (these are the dependency versions of the current latest version of pg).

To fix this, Zapatos would need to reference the PostgresInterval type exported by postgres-interval for Selectable.

Another more complicated consideration would be to allow customizing the default types used per data type, as the default parsers can be overridden at runtime (and there are legit reasons to do so, as some are legacy mistakes that won't be changed until a new major version of pg, e.g. numeric arrays are parsed like float arrays while numeric is parsed as a string and money arrays are parsed as string arrays, or plain dates are parsed as JS Date objects which shifts dates due to using using the local timezone, or to use newer JS features like BigInt for int8). It could work with a file like Zapatos generates for custom domain types that the user can edit. This would also make Zapatos more ready to deal with different versions of pg/pg-types where default parsers are set to change, e.g. date is parsed as a string in the newest version of pg-types, numeric arrays are fixed, and ranges are represented as a PostgresRange object.

In any case though I think the default should correctly represent what the latest version of pg does by default.

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

No branches or pull requests

1 participant