This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
smart-tag/db/insertDB.js

23 lines
809 B
JavaScript
Raw Normal View History

2021-03-12 12:34:06 +00:00
const con = require('./connect')
function insertDB(barcode, shelving, level){
2021-03-16 11:25:47 +00:00
con.con.connect(function(err) {
2021-03-12 12:34:06 +00:00
if (err) throw err;
2021-03-16 11:25:47 +00:00
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");
});
2021-03-12 12:34:06 +00:00
});
2021-03-12 12:54:21 +00:00
}
exports.insertDB = insertDB;