© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
3 replies
Lostra

"onConflictDoUpdate" fails with error in Array.flatMap

I am trying to run an upsert function, and update the values if it already exists. Now I might be completely in the wrong with the code.

I have made a base "repository" class that has the upsert function simplified as follows:

protected async upsert(
  data: typeof this.schema.$inferInsert | typeof this.schema.$inferInsert[]
){
  return await this.repository.insert(this.schema).values(data).onConflictDoUpdate({
    target: this.schema.id,
    set: data
  });
}
protected async upsert(
  data: typeof this.schema.$inferInsert | typeof this.schema.$inferInsert[]
){
  return await this.repository.insert(this.schema).values(data).onConflictDoUpdate({
    target: this.schema.id,
    set: data
  });
}


now I have tried the upsert in a loop for the array is the data happens to be an array, did not do anything, getting the same error.

 Cannot read properties of undefined (reading 'name')
    at file:///var/task/shared/modules/syncer/handlers/sync.mjs:729:921
    at Array.flatMap (<anonymous>)
    at UDe.buildUpdateSet (file:///var/task/shared/modules/syncer/handlers/sync.mjs:729:848)
    at QueryPromise.onConflictDoUpdate (file:///var/task/shared/modules/syncer/handlers/sync.mjs:723:85175)
    at $De.upsert (file:///var/task/shared/modules/syncer/handlers/sync.mjs:730:3003)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async $De.insertScan (file:///var/task/shared/modules/syncer/handlers/sync.mjs:730:6785)
 Cannot read properties of undefined (reading 'name')
    at file:///var/task/shared/modules/syncer/handlers/sync.mjs:729:921
    at Array.flatMap (<anonymous>)
    at UDe.buildUpdateSet (file:///var/task/shared/modules/syncer/handlers/sync.mjs:729:848)
    at QueryPromise.onConflictDoUpdate (file:///var/task/shared/modules/syncer/handlers/sync.mjs:723:85175)
    at $De.upsert (file:///var/task/shared/modules/syncer/handlers/sync.mjs:730:3003)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async $De.insertScan (file:///var/task/shared/modules/syncer/handlers/sync.mjs:730:6785)
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

onConflictDoUpdate array
Drizzle TeamDTDrizzle Team / help
3y ago
onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
5w ago
Insert Schemas with onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
3y ago
Multiple `onConflictDoUpdate()`
Drizzle TeamDTDrizzle Team / help
2y ago