DT
Drizzle Team•5mo ago
smmmn

$returningId() can not read properties of undefined id

Hey everyone! šŸ‘‹ I’m running into an issue with onDuplicateKeyUpdate and $returningId(). I keep getting an error: ā€œCannot read properties of undefined (reading ā€˜id’)ā€ I use drizzle with mysql (Planetscale) Here’s the relevant snippet:
await db
.insert(schema.category)
.values(data)
.onDuplicateKeyUpdate({ set: { id: sql`id` } })
.$returningId();
await db
.insert(schema.category)
.values(data)
.onDuplicateKeyUpdate({ set: { id: sql`id` } })
.$returningId();

What I expect this to do: 1. Insert a new row into ⁠schema.category with whatever is in ⁠data.

2. If there’s a duplicate key, update the existing row’s ⁠id column to the same value . 3. Return the ⁠id of the inserted or updated row. Instead, I’m hitting the runtime error. What could be going wrong? Thanks in advance for any tips or pointers! šŸ™
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?