diff --git a/FillDB.js b/FillDB.js index e69de29..93cce93 100644 --- a/FillDB.js +++ b/FillDB.js @@ -0,0 +1,11 @@ +const con = require('./connectDB.js') + +con.con.connect(function(err) { + if (err) throw err; + console.log("Connected!"); + var sql = "INSERT INTO vn.smartTag (code, shelvingFk, `level`) VALUES('A0A3B8200DA9', 'ABC', 2);"; + con.con.query(sql, function (err, result) { + if (err) throw err; + console.log("1 record inserted"); + }); +}); \ No newline at end of file diff --git a/bindShelving.js b/bindShelving.js index 603a375..57b9b57 100644 --- a/bindShelving.js +++ b/bindShelving.js @@ -1,6 +1,7 @@ +const config = require('./config'); +const got = require('got'); + function bindShelving(barcode, shelving, level){ - const config = require('./config'); - const got = require('got'); (async() => { const info = await config.info let key = info.data.token; diff --git a/bindTicketShelving.js b/bindTicketShelving.js index f75e78e..1a96dc8 100644 --- a/bindTicketShelving.js +++ b/bindTicketShelving.js @@ -1,8 +1,6 @@ - const insert = require('./insertTicket'); const filter = require('./filter'); - var barcode = "A0A3B820690F"; var shelving = "ABC";///introducida por el usuario var collectionFk = '254'; diff --git a/mysql.js b/connectDB.js similarity index 59% rename from mysql.js rename to connectDB.js index 2dbec9a..766b418 100644 --- a/mysql.js +++ b/connectDB.js @@ -9,11 +9,4 @@ var con = mysql.createConnection({ port: 3307, }); -exports.con -con.connect(function(err) { - if (err) { - console.error('Error connecting: ' + err.stack); - return; - } - console.log("Connected!"); -}); \ No newline at end of file +exports.con = con; \ No newline at end of file diff --git a/insertShelving.js b/insertShelving.js index 09ce96e..33aab1f 100644 --- a/insertShelving.js +++ b/insertShelving.js @@ -1,6 +1,7 @@ +const config = require('./config'); +const got = require('got'); + function insertShelving(shelving, level){ - const config = require('./config'); - const got = require('got'); (async() => { const info = await config.info let key = info.data.token diff --git a/mariadb.js b/mariadb.js deleted file mode 100644 index 7c3224e..0000000 --- a/mariadb.js +++ /dev/null @@ -1,28 +0,0 @@ -const mariadb = require('mariadb'); -const config = require('./config'); - -const pool = mariadb.createPool({ - host: "test-db.verdnatura.es", - database: "vn", - user: config.userDev, - password: config.passwordDev, - port: 3307, - connectionLimit: 5 -}); -pool.getConnection() - .then(conn => { - - conn.query("SELECT 1 as val") - .then(rows => { // rows: [ {val: 1}, meta: ... ] - return conn.query("INSERT INTO smartTag value (?, ?)", [1, "mariadb"]); - }) - .then(res => { // res: { affectedRows: 1, insertId: 1, warningStatus: 0 } - conn.release(); // release to pool - }) - .catch(err => { - conn.release(); // release to pool - }) - - }).catch(err => { - //not connected - }); \ No newline at end of file