refactoring db
This commit is contained in:
parent
adba40861c
commit
fa80cd686e
|
@ -1,12 +1,12 @@
|
|||
const mysql = require('mysql');
|
||||
const config = require('../config');
|
||||
|
||||
var con = mysql.createConnection({
|
||||
host: "test-db.verdnatura.es",
|
||||
database: "vn",
|
||||
user: config.userDev,
|
||||
password: config.passwordDev,
|
||||
port: 3307
|
||||
let con = mysql.createConnection({
|
||||
host: 'test-db.verdnatura.es',
|
||||
database: 'vn',
|
||||
user: config.userDev,
|
||||
password: config.passwordDev,
|
||||
port: 3307
|
||||
});
|
||||
|
||||
exports.con = con;
|
||||
exports.con = con;
|
||||
|
|
14
db/create.js
14
db/create.js
|
@ -1,11 +1,11 @@
|
|||
const con = require('./connect.js')
|
||||
const con = require('./connect.js');
|
||||
|
||||
con.con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
var sql = "CREATE TABLE smartTag2 (code VARCHAR(100) PRIMARY KEY, shelvingFk VARCHAR(10) FOREIGN KEY REFERENCES vn.shelving(code), level INT(11))";
|
||||
con.con.query(sql, function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("Table created");
|
||||
console.log('Connected!');
|
||||
let sql = 'CREATE TABLE smartTag2 (code VARCHAR(100) PRIMARY KEY, shelvingFk VARCHAR(10) FOREIGN KEY REFERENCES vn.shelving(code), level INT(11))';
|
||||
con.con.query(sql, function(err, result) {
|
||||
if (err) throw err;
|
||||
console.log('Table created');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const con = require('./connect')
|
||||
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}')
|
||||
function insertDB(barcode, shelving, level) {
|
||||
con.con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
// console.log("Connected!");
|
||||
let sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}')
|
||||
THEN
|
||||
UPDATE vn.smartTag
|
||||
SET shelvingFk = '${shelving}', level = ${level}
|
||||
|
@ -14,10 +14,10 @@ function insertDB(barcode, shelving, level){
|
|||
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");
|
||||
});
|
||||
con.con.query(sql, function(err, result) {
|
||||
if (err) throw err;
|
||||
// console.log("1 record inserted");
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.insertDB = insertDB;
|
||||
exports.insertDB = insertDB;
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
const con = require('./connect')
|
||||
|
||||
function maxWagon(collectionFk, callback){
|
||||
const con = require('./connect');
|
||||
|
||||
function maxWagon(collectionFk, callback) {
|
||||
let consSql = `SELECT MAX(tc.wagon)
|
||||
FROM ticketCollection tc
|
||||
WHERE tc.collectionFk = ${collectionFk}`;
|
||||
con.con.query(consSql, function (err, result, fields) {
|
||||
con.con.query(consSql, function(err, result, fields) {
|
||||
console.log(result);
|
||||
callback(null,result);
|
||||
callback(null, result);
|
||||
});
|
||||
}
|
||||
|
||||
exports.maxWagon = maxWagon;
|
||||
exports.maxWagon = maxWagon;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const con = require('./connect')
|
||||
const con = require('./connect');
|
||||
|
||||
con.con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
var sql = `INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES
|
||||
console.log('Connected!');
|
||||
let sql = `INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES
|
||||
('A0A3B8288AB1', 'ABC', 1),
|
||||
('A0A3B8288AB2', 'ABC', 2),
|
||||
('A0A3B8288AB3', 'ABC', 3),
|
||||
|
@ -13,8 +13,8 @@ con.con.connect(function(err) {
|
|||
('A0A3B8299CD3', 'DEF', 3),
|
||||
('A0A3B8299CD4', 'DEF', 4)
|
||||
;`;
|
||||
con.con.query(sql, function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("records inserted");
|
||||
con.con.query(sql, function(err, result) {
|
||||
if (err) throw err;
|
||||
console.log('records inserted');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
const con = require('./connect')
|
||||
const con = require('./connect');
|
||||
|
||||
|
||||
function select(collectionFk, callback){
|
||||
function select(collectionFk, callback) {
|
||||
let consSql = `SELECT t.id AS Ticket, c.name AS Client, am.name AS Agency, tc.level AS Level, tc.wagon AS Wagon
|
||||
FROM ticketCollection tc
|
||||
JOIN ticket t ON t.id = tc.ticketFk JOIN client c ON t.clientFk = c.id
|
||||
|
@ -9,13 +8,11 @@ function select(collectionFk, callback){
|
|||
WHERE tc.collectionFk = ${collectionFk}
|
||||
ORDER BY tc.wagon, tc.level`;
|
||||
|
||||
con.con.query(consSql, function (err, result, fields) {
|
||||
con.con.query(consSql, function(err, result, fields) {
|
||||
console.log(result);
|
||||
callback(null,result);
|
||||
callback(null, result);
|
||||
});
|
||||
}
|
||||
|
||||
exports.select =select;
|
||||
|
||||
|
||||
exports.select = select;
|
||||
|
||||
|
|
Reference in New Issue