A way to make a custom type generatedAlwaysAsIdentity
I've tried the following ways to achive this, but none of them work.
10 Replies
all issues related to this on github were closed with the release of generatedAlwaysAs and generatedAlwaysAsIdentity, but none of those two actually fix this issue as you can't do something like:
This is quite literally what the docs say you can do
Drizzle ORM - PostgreSQL column types
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
No need for a custom type
i do need to use a custom type. to do some custom encoding/decoding to the integer coming from/going to the database
think something like the following, for the sake of simplicity
There’s a trick that’s nowhere in the docs
Can you put this in drizzle-run so I can show you?
here you go https://drizzle.run/vq6b9jghc22sjfexzxqe71br
Drizzle Run
New starter 01 playground - Drizzle Run
Here you go https://drizzle.run/fgcr043w4ws7phw6m74ofchl
The only problem with this approach is that it's not reusable, you need to assign those methods to each column where you want to use it
Wait, that might not work for you anyway. When I did something like this a long time ago, I wasn't changing the type, just performing some logic. This will show as number at compile time but it will be a string a run time
So, don't use it
yeah I wish there was a simple .transform function available on all types similar to zod's
but thank you for the attempt anyway