Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special handling for SQL IN operator in DatabaseSync for queries #57102

Closed
mydoghasfleas opened this issue Feb 17, 2025 · 3 comments
Closed
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@mydoghasfleas
Copy link

What is the problem this feature will solve?

Being able to use the SQL IN operator is not possible without a workaround; see https://stackoverflow.com/questions/79441096/using-sql-in-operator-with-databasesync-in-node-sqlite

What is the feature you are proposing to solve the problem?

Being able to do a query like this, where parameters to an IN operator in the WHERE clause can be substituted by an array of values:

const stmt = conn.prepare(`select name from people where id in (?)`);
res = stmt.get([100,200,300])

What alternatives have you considered?

Only the workaround in the above linked Stackoverflow question, where you have to make provision for each value individually in the query (which would require a new prepared statement each time):

const values = [100,200,300];

// 3 values, so need 3 params: ?,?,?
const params = values.map(_=>'?').join(',');

const stmt = conn.prepare(`select name from people where id in (${params})`);
res = stmt.get(values);
@mydoghasfleas mydoghasfleas added the feature request Issues that request new features to be added to Node.js. label Feb 17, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Feb 17, 2025
@targos
Copy link
Member

targos commented Feb 17, 2025

How would that work? Does sqlite support binding arrays to prepared statements?

@cjihrig
Copy link
Contributor

cjihrig commented Feb 17, 2025

Does sqlite support binding arrays to prepared statements?

Not according to this Stack Overflow post. I don't think this is something we should try to support.

@mydoghasfleas
Copy link
Author

My bad. That was a gap in my knowledge about prepared statements.

@targos targos closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Archived in project
Development

No branches or pull requests

3 participants