-
Similar to how serial('id') work, I was wondering if there is a way to create an id field with default value set by JS, something like the following: export const user = mysqlTable(
"User",
{
id: varchar("id", { length: 191 })
.primaryKey()
.default(crypto.randomUUID())
.notNull(),
name: varchar("name", { length: 191 }).notNull(),
...
},
(table) => {
return {
...
};
}
); Thanks for the help. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 5 replies
-
It's not possible right now, but will be possible soon |
Beta Was this translation helpful? Give feedback.
-
+1 on this feature. |
Beta Was this translation helpful? Give feedback.
-
+1. something like how prisma does it with |
Beta Was this translation helpful? Give feedback.
-
Won't something like this work?
|
Beta Was this translation helpful? Give feedback.
-
This has been implemented in v0.28.3 but you'll need to update to v.28.5. The new |
Beta Was this translation helpful? Give feedback.
-
as of latest version this works: id: uuid().primaryKey().defaultRandom(), |
Beta Was this translation helpful? Give feedback.
This has been implemented in v0.28.3 but you'll need to update to v.28.5. The new
.$default
and.$defaultFn
methods lets you register a function that will be called on insert/update if not value is passed.