onConflictDoNothing is not returning values

Hey, Given the following query:
const competition = await db
.insert(competitions)
.values({
name: data.competition,
})
.onConflictDoNothing()
.returning();
const competition = await db
.insert(competitions)
.values({
name: data.competition,
})
.onConflictDoNothing()
.returning();
It only returns the data when it has inserted unique row, but when row exists, it doesn't return me the existing row. The behaviour I am seeking, is if the row exists, do not insert it, but give it back to me anyway, because I need to know the ID.
3 Replies
Patryk
PatrykOP14mo ago
As a work around I implemented onConflictDoUpdate() for now. And I update the updated_at timestamp in the table. However I dont think thats the best thing to do, if we aren't actually insert or upserting data then we shouldn't do anything
Angelelz
Angelelz14mo ago
This might be a behavior from the driver itself where there is nothing drizzle can do Because if the database is doing nothing, it might just be it's behavior to not retrurn anything
Patryk
PatrykOP14mo ago
hmm ok, I am using turso driver. I will test with something else if this still happens
Want results from more Discord servers?
Add your server