I have an array of data I want to insert into SQL:
let arr = [
{name:"john", age:8, country:"america"},
{name:"jack", age:9, country:"england"},
{name:"bob", age:12, country:"france"},
{name:"lance", age:6, country:"spain"}
]
I am using MySQL2 library with Node.js. And this is what I am doing right now:
const transfer = async() => {
for(person of arr){
let sql = `INSERT INTO users(name, age, country) VALUES("${person.name}", ${person.age}, "${person.country}")`;
const [res, _] = await db.execute(sql);
}
}
This works fine, but is there's method in which I can enter all the objects in arr in one SQL query (vs. a query for every insert)?