2
It is the following I tried to search but I did not find any solution, to try to create a function in the model of my application that will return the data of the query in the database. This function would be called in my controller which would later be sent to the page file.
Function making the query
exports.show = function(){
var result;
connection.getConnection(function(err, connection){
connection.query('select 1 + 1 as teste', function(err, rows){
this.result = rows[0].teste;
connection.release();
console.log('---->', this.result);
return this.result;
});
});
};
Controller
var Model = require('../models/Models');
exports.Index = function(request, response){
response.pageInfo = {};
response.pageInfo.title = 'Users';
response.pageInfo.users = Model.show();
response.render('user/index', response.pageInfo);
};
And the page . jade
extends ../layout
block content
h1 #{users}
And by executing it this way it simply doesn’t print the value on the page, but on the console it works.
That’s right, man. I had done in a way that when loading the page for the second time appeared the result of the database (Mysql), but I did following its instructions and it worked here. Thank you!!!!!! (I started studying Node.js two days ago and I’m already very excited about it)
– Liw. S.
@Liw.S. great! If you want you can mark the answer as accepted :)
– Sergio