Node-sqlite3: Add ability for sqlite to handle array parameters

Created on 12 Jan 2017  路  3Comments  路  Source: mapbox/node-sqlite3

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.

Most helpful comment

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);

All 3 comments

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);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hersoncruz picture hersoncruz  路  27Comments

Aminadav picture Aminadav  路  16Comments

ira-gordin-sap picture ira-gordin-sap  路  15Comments

creationix picture creationix  路  22Comments

sveinnM picture sveinnM  路  25Comments