So I'm messing around with Koa.js and generators, just threw together a simple site for demo purposes. I'm using sqlite with node-sqlite3
and Q for promises. Here's my db code:
module.exports.getLogs = function(){
var deferred = Q.defer();
var results = [];
db.serialize(function(){
db.each("SELECT ipAddress, action, details, timestamp FROM logs", function(err, row) {
results.push({
ipAddress: row.ipAddress,
action: row.action,
details: row.action,
timestamp: new Date(row.timestamp)
});
}, function(){
deferred.resolve(results);
});
});
return deferred.promise;
}
So basically I'm just Q.defer to "promisify" the call to the database. Then, in my koa route, I have this:
app.get('/logs', function *(){
var logs = yield db.getLogs();
yield this.render('logs', {logs: logs});
});
The issue I'm having is that the request is just hanging, the browser never gets a response. What's really strange is that if I put a console.log statement after the yield db.getLogs()
I see the results from the db just fine. The view is there, everything seems like it should work, but it simply doesn't. Any help would me much appreciated!