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

Fix: Support PGSQL Decimal type #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jarekcieslak
Copy link

I've noticed that DB schemas containing fields defined as DECIMAL generate types as strings. Here's an example:

CREATE TABLE booking_pricing
(
    id     INT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    total_price            DECIMAL(15,4)           NOT NULL,
)

produces:

export type BookingPricing = {
  id: number;
  total_price: string;
};

instead of :

export type BookingPricing = {
  id: number;
  total_price: number;
};

@jarekcieslak jarekcieslak changed the title Support PGSQL Decimal type correctly Fix: Support PGSQL Decimal type May 4, 2022
@jarekcieslak jarekcieslak marked this pull request as ready for review May 4, 2022 11:41
@koistya
Copy link
Member

koistya commented May 4, 2022

@jarekcieslak by default knex / pg-types returns decimal/numeric values as strings I believe; if you need them to be numeric instead, in addition to overriding generated data type, you would also need to tweak pg-types settings:

https://github.com/brianc/node-pg-types

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

Successfully merging this pull request may close these issues.

None yet

2 participants