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

How to detect when at attempt is made to serialize BigInt to JSON? #3075

Open
gajus opened this issue Oct 6, 2023 · 0 comments
Open

How to detect when at attempt is made to serialize BigInt to JSON? #3075

gajus opened this issue Oct 6, 2023 · 0 comments

Comments

@gajus
Copy link
Contributor

gajus commented Oct 6, 2023

For context, I want to throw an error when an attempt is made to serialize BigInt to a JSON.

gajus/slonik#515

The reason being that handling values in such a way may produce unexpected results:

test.only('serializes BigInt to JSON', async (t) => {
  const pool = await createPool(t.context.dsn, {
    PgPool,
  });

  const result = await pool.oneFirst(sql.unsafe`
    SELECT json_object_agg('foo', ${BigInt(
      1_000_000_000_000_000_001n,
    )}::bigint)
  `);

  t.deepEqual(result, {
    foo: 1_000_000_000_000_000_000,
  });

  await pool.end();
});

I would therefore rather require that the end user cast the value to ::text or whatever else.

I am trying to figure out which part of the node-postgres API I could use to tap into this happening?

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