Open dcposch opened 3 months ago
Happy to submit a PR, let me know.
Hello! I just added the CLI option --numeric-parser
which will be released in kysely-codegen@0.16.0 soon. 👌
// --numeric-parser=string (default)
safeNumeric: '9007199254740991'
unsafeNumeric: '9007199254740992'
// --numeric-parser=number-or-string
safeNumeric: 9007199254740991
unsafeNumeric: '9007199254740992'
// --numeric-parser=number
safeNumeric: 9007199254740991
unsafeNumeric: 9007199254740992
It will also set the selection type to string
, number | string
or number
accordingly.
Hello! I just added the CLI option
--numeric-parser
which will be released in kysely-codegen@0.15.0 soon. 👌
I am on 0.15.0 but I don't see the option.
Hello! I just added the CLI option
--numeric-parser
which will be released in kysely-codegen@0.15.0 soon. 👌I am on 0.15.0 but I don't see the option.
Hello! Sorry, I meant 0.16.0. It should come out soon.
Cool! My application uses bigint for some critical tables and I don't want to parseInt dozens of times if there's a better solution coming down the pipe. Any ETA on the update?
Should be released in kysely-codegen@0.16.0! 🚀
Hello! I just added the CLI option
--numeric-parser
which will be released in kysely-codegen@0.16.0 soon. 👌// --numeric-parser=string (default) safeNumeric: '9007199254740991' unsafeNumeric: '9007199254740992' // --numeric-parser=number-or-string safeNumeric: 9007199254740991 unsafeNumeric: '9007199254740992' // --numeric-parser=number safeNumeric: 9007199254740991 unsafeNumeric: 9007199254740992
It will also set the selection type to
string
,number | string
ornumber
accordingly.
Am I using it wrong?
kysely-codegen@0.16.5
bun kysely-codegen --out-file=src/lib/db/types.ts --numeric-parser=number
Generates:
export type Int8 = ColumnType<string, bigint | number | string, bigint | number | string>;
It's possible that this doesn't work for pre-defined types (like Int8
), but I will have to investigate.
Hey, just making a note to say I'm getting a similar issue using kysely-codegen@0.16.8
.
export type Int8 = ColumnType<string, bigint | number | string>;
The command I'm running is: kysely-codegen --out-file ./src/types/db-schema.ts --dialect=postgres --numeric-parser=number --camel-case
.
Summary
Currently, a Postgres
numeric
can be inserted as number, but only queried as a string.I know that Postgres
numeric
types can hold values larger than the ~2^53 largest JS integer, so I understand the rationale for allowing strings, but not why it's mandatory.Proposed fix
Current:
We could simplify to:
Upvote & Fund