I am currently working on a Typescript project where I am looking to optimize my Insert function by creating one Insert statement for all the elements in an object, rather than generating multiple Inserts for each array item.
Here is the code snippet of my current function:
public async insert() {
let object = [{ cod: 'CO',
file: 'CO_SER.csv',
exists: 1},
{ cod: 'ES',
file: 'ES_INS.csv',
exists: 1 } ];
for (let elem of object) {
let insert = `INSERT INTO databaseID VALUES ("${elem.cod}", "${elem.file}", ${elem.exists})`;
}
}
Currently, the output looks like this:
INSERT INTO databaseID VALUES ("CO", "CO_SER.csv", 1)
INSERT INTO databaseID VALUES ("ES", "ES_INS.csv", 1)
However, I aim to achieve the following desired outcome:
INSERT INTO databaseID VALUES ("CO", "CO_SER.csv", 1), ("ES", "ES_INS.csv", 1)