qb icon indicating copy to clipboard operation
qb copied to clipboard

updateOrInsert should return "generatedKey" somehow, even on updates...

Open Daemach opened this issue 4 years ago • 5 comments

I love the update or insert, but really need a key back, either the inserted key or actual key from the updated record (my where clause checks a fk).

The documentation is ambiguous. If the following is how it actually works, then perhaps adding one more argument to updateOrInsert specifying idField = "id" would work. If that argument exists, assume I want a key and fall back to using whereIn, limit 1 instead of exists and return the id field, setting result.generatedKey - this would be non-performant, but I accept the hit in this situation.

Performs an update statement if the configured query returns true for exists. Otherwise, performs an insert statement.

If the following is how it actually works, then it would be even less performant, but still immensely helpful

If the configured query returns 0 records, then an insert statement is performed.

Daemach avatar Feb 17 '21 20:02 Daemach