why doesn't `onConflictDoUpdate` allow strings as targets?

Can't do this...
await db
.insert(schema.users)
.values({
role,
username,
})
.onConflictDoUpdate({
target: "users_lower_username_uidx",
set: {
role,
updatedAt: sql`now()`,
},
})
await db
.insert(schema.users)
.values({
role,
username,
})
.onConflictDoUpdate({
target: "users_lower_username_uidx",
set: {
role,
updatedAt: sql`now()`,
},
})
3 Replies
ly
lyOP5mo ago
the only alternative is to have a lowerUsername column which is fine but I shouldn't have to.
oke
oke5mo ago
Feel like if you do sql.raw("users_lower_username_uidx") it might work How did you create this index?
ly
lyOP5mo ago
target only takes IndexColumn | IndexColumn[] and i used uniqueIndex which is not a compatible type

Did you find this page helpful?