Closed alpapan closed 4 hours ago
The issue here is not with drizzle. Drizzle returns the correct datatype for the column as specified in the schema. The issue is when you want to send it via fastify
to the client, and it doesn't only affect fastify, express
too would be affected. You can serialize the data yourself before sending it to the client. See options here
Perhaps. But if you notice my post you will see that foreign key references are set the mode to number even if the referenced column is a bigserial/bigint.
It would work out of the box if drizzle was consistent and set the mode to number for bigserial during column definition and provided the same comment as it does for columns with foreign key references.
If it was me, I would make sure the mode was identical in both definitions, both bigint or number. I would also add a note in the documentation somewhere.
Up to you if you and how you want to interact with the user community. After an hour I learnt how to fix it on my system.
What version of
drizzle-orm
are you using?0.30.10
What version of
drizzle-kit
are you using?0.21.4
Describe the Bug
Putting here in case it is of help:
When using Drizzle with fastify/view (8.2.0) and nest js (10), bigserials have a mode of bigint which croaks due to json stringify (see this fastify issue and stringify
The following was created by drizzle-kit with a postgres schema that has id as a bigserial and it will croak with
TypeError: Do not know how to serialize a BigInt
The quick solution is to change the mode from bigint to number.
I'm not sure if it is perhaps a good idea to either document or set the default drizzle-kit output to
mode: number
I note that when drizzle-kit sees a bigint column that is not (big)serial, then it sets the mode to number by default and provides a comment. So perhaps this could apply to bigserial too (since these two things are linked in the database: a bigserial id may have a bigint foreign key somewhere.
DRIZZLE-KIT output from introspect:
Expected behavior
No response
Environment & setup