Trying to generate a short id via a random string function
Hi everyone,
In my schema I have:
I now want to add a shortId field, which will use something like:
Which would use this:
So that I can have a shortId string generated each time, much like the normal uuid for the id field.
13 Replies
So what is your question?
Hey!
I want the shortId to use the generateRandomString function to populate when a new item for that schema is generated on the database.
Drizzle introduced the
$default()
method on the column definitions that accepts a javascript function that should return the value that you want to insert as defaultThis is exactly what you're looking for
Thank you, I will try that now, I assume it's something along the lines of:
Be careful, it's
.$default
not .default
.default()
only accepts SQL
it's the default at database levelhmm when I try $default I get:
You need the newer versions of drizzle
thanks! Going to try the following now:
Just a side question, since updating, the following is deprecated:
But it shows too much data (the whole PgTable):
Take a look at the docs: https://orm.drizzle.team/docs/goodies
Goodies - DrizzleORM
Drizzle ORM | %s
I so have trouble with the search functionality on the documentation. I've searched for inferselectmodel and infermodel before I asked etc but nothing shows.
Just wondering if the search isn't great, or if it's something on my side.
You might be onto something. In this case it's kinda hard to get to that page. You have to know what you're looking for