meteor-pg
meteor-pg copied to clipboard
Modify results before return
Hi, I've been trying to find a way to modify the select results before returning them to the client. This is what I'm doing at the moment:
var r = liveDb.select("select * from table);
r.on('update', function(diff, data){
diff.added[0].newProperty = "xxx"
diff.added[0].existingProperty = diff.added[0].existingProperty + 1;
// The above 2 lines work fine and the client receives the updated results.
// I cannot do the following though:
selectMoreData(diff.added[0].id, function(res){
diff.added[0].secondQuery = res;
});
});
return r;
**Note: selectMoreData() is a method that uses pg.connect to query more data.
It does work as long as I don't call the async method. Is there a better approach to what I'm trying to do? I'm not even sure if the diff.added[0] is the best way validate results.
I'm not sure of any workaround for this case. Why can't you simply write a more complex SQL query that formats the data as you want it in the Postgres server?