Update and return a single row only when using .update()?
Hi,
I have the following drizzle code which updates levels in a table.
Is it possible to only update a single row in the levels table instead of all that match the
where
clause? I'm asking this because I want the returning()
value to be a single object instead of an array of objects.
I'm fairly new to pg and drizzle so I apologise if it's a silly question xD2 Replies
All of drizzle’s APIs (except for a specific case for SQLite, iirc) will always return an array even if only a single row is matched
This matches the behavior of the underlying database drivers, and generally drizzle doesn’t have a reliable way of knowing that a query can only return one row
Know that you’re returning only one row? Get the first element of the returned array, maybe validating that the array length is indeed one to be safe
Oh I see. Thanks. I've been getting the first element of the returned array so I think I'll stick with that.