const con = require('./connect') function insertDB(barcode, shelving, level){ con.con.connect(function(err) { if (err) throw err; //console.log("Connected!"); var sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}') THEN UPDATE vn.smartTag SET shelvingFk = '${shelving}', level = ${level} WHERE code='${barcode}'; ELSE INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES ('${barcode}', '${shelving}', ${level}); END IF;`; con.con.query(sql, function (err, result) { if (err) throw err; //console.log("1 record inserted"); }); }); } exports.insertDB = insertDB;