I'm working with the "architect" plugin system package. I've created two plugins one's named "database" and one "test".
database provides database and test consumes database.
following issue happens with this implementation:
when calling my method getClientOnlineTimeById from the test plugin the method will process and exec the callback but when using the passed data in my callback function at for example setting a variable it is undefined everytime. tried promise as well nothing changed still undefined.
snip from database.js:
getClientOnlineTimeById: function(clientDatabaseId, callback) {
// Get a mysql connection from our created pool
pool.getConnection(function(err, conn){
conn.release();
if(err) {
throw err;
}
// exec our query to get our client with our clientId
conn.query("SELECT `time` FROM `onlinetime` WHERE `clientDatabaseId` = ?", [clientDatabaseId], function(err, rows){
if(err){
// call callback and let it handle the error
callback(err);
}
if(options.debug)
console.log("[Database:getClientOnlineTimeById] returning row with data: " + JSON.stringify(rows));
// call callback with data
callback(null, rows);
});
});
}
snip from test.js:
var onlineTime = undefined;
db.getClientOnlineTimeById("5", function(err, data) {
if(err) {
throw err;
}
onlineTime = data;
});
console.log("onlineTime: \n" + JSON.stringify(onlineTime));
console log:
onlineTime: undefined
[Database:getClientOnlineTimeById] returning row with data:[{"time":34501218327}] <-- This is the console.log from the getClientOnlineTimeById function
when i add a setTimeout infront of my console.log in the test.js it works, but i need the data as soon as i'm in the callback function. Is there anything i'm missing?