-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
Support defining property default values at the schema level, for more concise inserts and avoiding repetition.
Example:
const todoSchema = z.object({
id: z.string().default(()=> crypto.randomUUID()),
text: z.string().default(""),
completed: z.boolean().default(false),
createdAt: z.coerce.date().default(()=> new Date()),
updatedAt: z.coerce.date().default(()=> new Date()),
})
So that you can simply write:
todoCollection.insert({
text: newTodoText,
});
Instead of:
todoCollection.insert({
// Random temporary id.
id: Math.floor(Math.random() * 1000000),
text: newTodoText,
completed: false,
created_at: new Date(),
updated_at: new Date(),
});
I think only needed for inserts.
Metadata
Metadata
Assignees
Labels
No labels