I have a SQL file that contains a query like this:
SELECT * WHERE id IN ($1)
The SQL query is read and passed into a TypeORM query with an array of parameters.
const result = await this.entityManager.query(myQuery, parameters);
I want the parameters
to be an array with only one value that combines all the IDs I want to search for as a single string. This way, I can use my SQL file regardless of how many IDs I need to filter by.
I've attempted to format the parameters
in a way that keeps only $1
irrespective of the number of items in my array:
const ids = ['1', '2', '3'];
const parameters = [ids.join(",")];
or
const parameters = ["'" + ids.join(",") + "'"];
and so on
Unfortunately, I haven't found a syntax that successfully achieves this. Is there a way to make this work?