0

This code, using post as object, is working.

let post = {id: 1, name: 'Terminal 1'};
db.query('INSERT INTO terminal SET ?', post);

This code, using post as array, is not working.

let post = [
    {id: 1, name: 'Terminal 1'},
    {id: 2, name: 'Terminal 2'}
];
db.query('INSERT INTO terminal SET ?', post);
or 
db.query('INSERT INTO terminal SET ?', [post]);
0

1 Answer 1

1

You can call query for every object in array using for..of cycle:

let post = [
{id: 1, name: 'Terminal 1'},
{id: 2, name: 'Terminal 2'}
]
for (let object of post) {
db.query('INSERT INTO terminal SET ?', object)
}
Sign up to request clarification or add additional context in comments.

1 Comment

It is an option, but I'd preffer to solve it like a bulk insert to reduce request to the data base

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.