Custom UUID

When declaring my schema, I would like to provide a custom UUID generator for the id column. At the moment, it's just int autoincrement or serial from drizzle. Is there a way to replace this with something like ulid with a prefix?
6 Replies
Nycheporuk
Nycheporuk17mo ago
looks like as for now the only option is to provide id on each insert
const id = randomUUID();
await db.insert(table).values({
..data,
id,
});
const id = randomUUID();
await db.insert(table).values({
..data,
id,
});
MAST
MAST17mo ago
Yeah, I just define the column as a varchar and generate the id myself and insert it.
pandareaper
pandareaper17mo ago
Depending on your DB, if you are storing UUIDs (and even ULIDs) then you should really store them as BINARY(16) rather than varchar. ULIDs and UUIDs are binary compatible (128-bit)
Josh
JoshOP16mo ago
Right, I went with this option as well Noted. Thanks!
Andrii Sherman
Andrii Sherman16mo ago
GitHub
Release 0.28.3 · drizzle-team/drizzle-orm
🎉 Added SQLite simplified query API 🎉 Added .$defaultFn() / .$default() methods to column builders You can specify any logic and any implementation for a function like cuid() for runtime defaul...
Andrii Sherman
Andrii Sherman16mo ago
Note there may be some issues with types for esm projects, which we are fixing now and goint to release fixes in 0.28.4
Want results from more Discord servers?
Add your server