looking for some solutions? You are welcome.

SOLVED: MySQL SET inserts only the first item in a list

user829174:

I am using NodeJs msyql,

var telemetryItemList = [
    { 'created_at': createdAt, 'device_type': deviceType + '1', 'device_serial': deviceSerial , 'metric_name': metricName, 'metric_value': metricValue },
    { 'created_at': createdAt, 'device_type': deviceType + '2', 'device_serial': deviceSerial , 'metric_name': metricName, 'metric_value': metricValue },
    { 'created_at': createdAt, 'device_type': deviceType + '3', 'device_serial': deviceSerial , 'metric_name': metricName, 'metric_value': metricValue },
    { 'created_at': createdAt, 'device_type': deviceType + '4', 'device_serial': deviceSerial , 'metric_name': metricName, 'metric_value': metricValue },
    { 'created_at': createdAt, 'device_type': deviceType + '5', 'device_serial': deviceSerial , 'metric_name': metricName, 'metric_value': metricValue }
];

pool.getConnection((err, conn) => {
    if(err) {
        throw new Error('Could not get DB connection');
    }
    conn.query(`INSERT INTO ${Config.tableName} SET ?`, telemetryItemList, (err, res) => {
    .
    .
    .

The code above inserts only the first row of the list, why is that?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent