I'm working on the NodeJS framework, where the sql is executed after the main body.
I have used the basic sql connection block and am not sure how to integrate async or callbacks in the block.
My code is below:
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit: 100,
host: "localhost",
user: "...user...",
password: "...pw...",
database: "...db..."
});
... ... ...
app.get('/*', function(req, res) {
var sql = mysql.format("SELECT * FROM test_rest WHERE location=? LIMIT 2", [user_input]);
pool.getConnection(function(err,connection) {
if (err) throw err;
connection.query(sql, function (err, result, fields) {
connection.release();
if (err) throw err;
});
});
var jsonResponse = [];
var obj = {};
obj["text"] = 'hi this is' + user_nsew_1;
jsonResponse.push(obj);
res.send(jsonResponse);
});