I am dynamically trying to pass the name of the table to SQL query in the part of express code below
Background Information::
- What i am passing as a (key,value) is the string which will be the name of a table in sql database
- why am i doing is to dynamically select the table based on a dynamic client request
Problem I am facing::
- Clearly i am not sunig the sql query correctly
- How to solve this
[ExpressCode]
app.get('/RestaurantDesc/:Key',function(request,response,next){
var keyName=request.params.Key;
var name_of_restaurants, RestaurantTimings;
async.series( [
// Get the first table contents
function ( callback ) {
connection.query('SELECT * FROM keyName', function(err, rows, fields)
{
console.log('Connection result error '+err);
name_of_restaurants = rows;
callback();
});
},
// Get the second table contents
function ( callback ) {
connection.query('SELECT * FROM RestaurantTimings', function(err, rows, fields)
{
console.log('Connection result error '+err);
RestaurantTimings = rows;
callback();
});
}
// Send the response
], function ( error, results ) {
response.json({
'restaurants' : name_of_restaurants,
'RestaurantTimings' : RestaurantTimings
});
} );
} );