node-sqlite3
node-sqlite3 copied to clipboard
Add ability for sqlite to handle array parameters
I want IN operator to work correctly with array params, for example:
SELECT * FROM table WHERE table.id IN ($1)
I would like $1 to be:
$1 = [1, 2, 3, 4] or $1 = ['firstId', 'secondId', 'thridId', '...']
So, it will generate query like SELECT * FROM table WHERE table.id IN (1, 2, 3, 4) where all id from the array are escaped.
Mysql driver handles such parameters very nicely.
also in #527 and #628 and #373 and #777
good
As a workaround you could do the following:
const ids = [1, 2, 3, 4];
const placeholders = ids.map(() => "?").join(",");
db.run(`SELECT * FROM table WHERE table.id IN (${placeholders})`, ids);
As a workaround you could do the following:
const ids = [1, 2, 3, 4]; const placeholders = ids.map(() => "?").join(","); db.run(`SELECT * FROM table WHERE table.id IN (${placeholders})`, ids);
The issue we ran into with that was:
SQLITE_ERROR: too many SQL variables
or something along those lines.
https://github.com/typeorm/typeorm/issues/190
The issue we ran into with that was:
SQLITE_ERROR: too many SQL variablesor something along those lines.
Try with :
const ids = [1, 2, 3, 4];
const placeholders = ids.map(() => "?").join(",");
db.run(`SELECT * FROM table WHERE table.id IN (${placeholders})`, ...ids);