Answer the question
In order to leave comments, you need to log in
Again this Promis?
I have this model:
connection = require('../lib/mysql');
var info = {};
var getBalance = function(id) {
return new Promise(function(resolve, reject){
connection.query('SELECT balance FROM Users WHERE id = ?', id, function(error, result, fields) {
if(error)
reject(error);
if(result[0]['balance'])
resolve(result[0]['balance']);
reject();
});
});
};
info.getBalance = function(id) {
getBalance(id).then(function(data){
console.log(data);
return data;
});
}
module.exports = info;
var model = require('./model');
console.log(model.getBalance(123123));
Answer the question
In order to leave comments, you need to log in
You forgot to return a promise
info.getBalance = function(id) {
return getBalance(id).then(function(data){
console.log(data);
return data;
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question