Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let express = require('express');
  2. let mysql = require('mysql')
  3.  
  4. let app = express();
  5.  
  6. let connection = mysql.createConnection({
  7.     user: "norbi",
  8.     password: "Iqevm7SDa6mZegZa",
  9.     host: "145.239.82.137",
  10.     port: 3306,
  11.     database: "mrc",
  12. });
  13.  
  14. app.set('port', process.env.PORT || 5000);
  15.  
  16. app.get('/', function(req, res){
  17.     connection.connect();
  18.  
  19.     connection.query(perform_query([62,63]), function (err, rows, fields) {
  20.         if (err){
  21.             throw err;
  22.         }
  23.        
  24.         let data = {}
  25.         for (let i in rows){
  26.             data['Array['+ i +']'] = rows[i];
  27.             i++;
  28.         }
  29.  
  30.         res.json(data)
  31.     });
  32.     connection.end();    
  33. });
  34.  
  35. function perform_query(...product_ids){
  36.     return 'SELECT products.id, products.code, products.category,'+
  37.     'categories.name_pol, categories.name_eng, categories.name_rus, categories.name_ger '+
  38.     'FROM products '+
  39.     'INNER JOIN categories ON categories.id = products.category '+
  40.     'WHERE products.id IN ('+ product_ids +');';
  41. }
  42.  
  43.  
  44. app.listen(app.get('port'), function(){
  45.     console.log('http://127.0.0.1:5000');
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement