I have a record ID of type bigint, and I would like to use it in the where clause of a Zapatos query, but I'm unable to use it directly:
async selectOneById(id: bigint): Promise<MyThing> {
return await db
.selectExactlyOne(
'my_cool_table',
{ id: id },
)
.run(pool);
}
This produces the type error:
error TS2322: Type 'bigint' is not assignable to type 'number | `${number}` | SQLFragment<any[], never> | ParentColumn<Column | undefined> | Parameter<number | `${number}`> | SQLFragment<any, number | ... 3 more ... | Parameter<...>> | undefined'.
I read through the docs, and I see examples of how to parse bigints out of the result of selecting from the database, but I don't see how to pass bigint values into Zapatos methods. chatgpt suggested doing:
`${Number(id)}`
But I'm pretty sure this would lead to precision loss and potentially query for the wrong ID.
The best I've come up with so far is basically doing a type conversation that lies about the type:
const bigIntToNumberTemplate = (value: bigint): `${number}` => `${value}` as `${number}`;
I'm wondering if I've missed any better options. Thanks!
I have a record ID of type
bigint
, and I would like to use it in thewhere
clause of a Zapatos query, but I'm unable to use it directly:This produces the type error:
I read through the docs, and I see examples of how to parse bigints out of the result of selecting from the database, but I don't see how to pass bigint values into Zapatos methods. chatgpt suggested doing:
But I'm pretty sure this would lead to precision loss and potentially query for the wrong ID.
The best I've come up with so far is basically doing a type conversation that lies about the type:
I'm wondering if I've missed any better options. Thanks!