Drizzle TeamDT
Drizzle Team3y ago
1 reply
gps.

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()

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(),


And finally the insert schema :
export const insertOrderSchema = createInsertSchema(orders)


Field validation is handled with zod :
pickupTime: z.coerce.string()


insertOrderParams :
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 ?
image.png
Was this page helpful?