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

Configure type mapping #37

Open
frankvollebregt opened this issue Sep 3, 2024 · 3 comments
Open

Configure type mapping #37

frankvollebregt opened this issue Sep 3, 2024 · 3 comments

Comments

@frankvollebregt
Copy link

Thank you for this cool and useful utility!

I've gotten everything working with my PostgresQL database, and noticed that all my BIGINT columns get returned as a string in the resulting Typescript interfaces.

I came across #15, which acknowledges this behavior and results in it being added for MySQL too. But I was wondering why the String approach was chosen instead of using the Javascript BigInt primitive.

Intuitively, it makes more sense to me to use and return BigInts as it corresponds more directly with the real data, but I assume there is a reasoning (compatibility?) for using a simple String instead.

In some rare cases, I want to compare two BIGINT values, say A > B, which works fine with Strings until one has more digits (e.g. '999' > '1000' results in true). Should I just find a work-around for these cases (maybe use some padding zeroes to start), or is there some sense in allowing the use of the BigInt primitive instead of a string?

And as an additional question, are there any options to influence the type mapping from the column types in my schema at all?

@yshrsmz
Copy link
Contributor

yshrsmz commented Sep 4, 2024

I think it's to keep sqlc simple. Just to keep it a thin wrapper for each DB driver libs.
Since node-mysql2 only supports number or string for BIGINT, converting to JavaScript BigInt type adds extra complexity to sqlc.

@ahmafi
Copy link

ahmafi commented Oct 17, 2024

But the Go generator has overrides for generated types. I think a similar override option would be nice in TypeScript too.

@AM1010101
Copy link

I would second this ability. My use case is be able to map decimal numbers in postgres to a number type in typescript.

Very much appreicate this tool overall and excited to see where it goes

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

4 participants