tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.24k stars 471 forks source link

[Question] Ability to bind parameters with array values? #1575

Closed Ben-CA closed 1 year ago

Ben-CA commented 1 year ago

This isn't an "issue" as much as a "question" (and if there isn't an answer, then it sort of is an issue).

I've posted on Stack Overflow asking if this setup has the ability to bind parameters with array values?

https://stackoverflow.com/questions/77404232/binding-dynamic-array-parameter-values-for-sql-with-nodejs

But so far I'm not getting any responses. Including it here for visibility.

I've reviewed the documentation and am not seeing anything regarding this.

dhensby commented 1 year ago

Yes, you can do it using the tagged template literal support. eg:

const pool = new ConnectionPool(config);
const req = pool.request();
const query = req.query`select * from [table] where id in (${[1,2,3]})`
query.then((res) => console.log(res);
Ben-CA commented 1 year ago

Great - thanks!

Might be something to consider adding some clarity on in the documentation.