DB insertion - Date field (mode: string) is using default value instead of passed value

Trying to insert an Order object which has a "pickupTime" Date field to db, but upon insertion the created item uses the model default value instead of the passed date. This is the insertion :
const [o] = await db.insert(orders).values(newOrder).returning()
const [o] = await db.insert(orders).values(newOrder).returning()
newOrder pickupTime value before insertion is the follow string : 2023-09-20T14:45:00.000Z After insertion, the pickupTime value I get is the a Date.now() string (2023-09-19T22:00:00.000Z) Field configuration in pgTable is :
pickupTime: date('pickupTime', { mode: 'string' }).notNull().defaultNow(),
pickupTime: date('pickupTime', { mode: 'string' }).notNull().defaultNow(),
And finally the insert schema :
export const insertOrderSchema = createInsertSchema(orders)
export const insertOrderSchema = createInsertSchema(orders)
Field validation is handled with zod :
pickupTime: z.coerce.string()
pickupTime: z.coerce.string()
insertOrderParams :
export const insertOrderParams = createSelectSchema(orders).omit({
id: true,
userId: true,
number: true,
date: true
})
export const insertOrderParams = createSelectSchema(orders).omit({
id: true,
userId: true,
number: true,
date: true
})
(the date field here is not the one I'm interested in) Any idea what could be happening ?
No description
1 Reply
gps.
gps.OP15mo ago
"""Solved""" my own problem by using a timestamp field instead of date. No idea what happened there
Want results from more Discord servers?
Add your server