Can prepared statements bind arrays for `IN (?)`

does anyone know if prepared statements can be bound with arrays? i'm trying to do a query like db.prepare('SELECT * FROM table WHERE status IN (?)').bind(['active','expired']).all(), would that work?
5 Replies
krofdrakula
krofdrakulaOP7mo ago
the alternative is to generate the SQL string and then spread into the bind() call, but was wondering if i could avoid that
kian
kian7mo ago
You'd need to create the ?'s in the string based on the length of the array
krofdrakula
krofdrakulaOP7mo ago
so the ? placeholder won't automatically expand the parameter into a list?
krofdrakula
krofdrakulaOP7mo ago
well crap 😐 ok, thanks for that answer, it's exactly what i needed
'?'.repeat(status.size).split('').join(', ')
'?'.repeat(status.size).split('').join(', ')
it is then.
Want results from more Discord servers?
Add your server