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

Invalid types for bigint and bigserial #23

Closed
elahti opened this issue Apr 24, 2020 · 1 comment
Closed

Invalid types for bigint and bigserial #23

elahti opened this issue Apr 24, 2020 · 1 comment

Comments

@elahti
Copy link

elahti commented Apr 24, 2020

It seems that sqltyper version 0.2.3 (I'm using PostgreSQL version 12 and pg 8.0.3) generates unexpected string types for bigint and bigserial fields.

Using table definition

create table t (
    a integer,
    b bigint,
    c bigserial
)

and query

insert into t (a, b, c) values (${a}, ${b}, ${c})

one gets following .ts code with sqltyper (removed comments from top of the file):

import { ClientBase } from 'pg'

export async function insertToT(
  client: ClientBase,
  params: { a: number | null; b: string | null; c: string },
): Promise<number> {
  const result = await client.query(
    `\
insert into t (a, b, c) values ($1, $2, $3)
`,
    [params.a, params.b, params.c],
  )
  return result.rowCount
}
@akheron
Copy link
Owner

akheron commented Apr 25, 2020

Bigint and bigserial are returned as strings by node-postgres, because all bigints don't fit in the JavaScript number type (53 bits of precision). See brianc/node-postgres#353. Sqltyper's output has to match the node-postgres runtime semantics.

@elahti elahti closed this as completed Oct 15, 2021
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

2 participants