Updating multiple rows with single SQL query doesn't work.
With the above code, I'm setting the
approved
column to be true
. ids
is an array of strings, that I convert to the form of 'id1', 'id2'
. Passing a single value into ids
works, but when more than one value is passed, nothing happens. There is no error returned.
Bizarrely, when I console log the generated sql query (in the case of multiple IDs) and execute it manually on my database, everything works fine. I suspect it's something to do with the sql
function, but I don't understand why it works when there's only one ID.3 Replies
Is there any reason that you would not just use this?
The difference between these two approaches is like this:
The way it binds the values in the query is the issue here. There is some SQL injection magic and possibly other transformations happening during the binding that breaks the first approach.
If there is some reason the 2nd approach doesn't work, you'll likely need to build your SQL step by step like this:
https://orm.drizzle.team/docs/sql#sqlempty
Drizzle ORM - Magic sql`` operator
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Ahh okay, I understand, thank you! I wasn't aware of the
.inArray()
function ðŸ˜