Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active January 3, 2016 23:29
Show Gist options
  • Save robwormald/8534985 to your computer and use it in GitHub Desktop.
Save robwormald/8534985 to your computer and use it in GitHub Desktop.
stream: function(collectionName, options, stream) {
// options is a standard criteria/options object (like in find)
// stream.write() and stream.end() should be called.
// for an example, check out:
// https://github.com/balderdashy/sails-dirty/blob/master/DirtyAdapter.js#L247
var collection = _modelReferences[collectionName];
getQBModel(collectionName,options,function(err,model){
var responseStream = qbRequest(collection,model,options)
responseStream.pipe(qbStream(collection,model)).pipe(stream)
})
},
/**
*
* REQUIRED method if users expect to call Model.find(), Model.findOne(),
* or related.
*
* You should implement this method to respond with an array of instances.
* Waterline core will take care of supporting all the other different
* find methods/usages.
*
* @param {[type]} collectionName [description]
* @param {[type]} options [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
find: function(collectionName, options, cb) {
// If you need to access your private data for this collection:
var collection = _modelReferences[collectionName];
getQBModel(collectionName,options,function(err,model){
qbRequest(collection,model,options,function(err,response,body){
qbParser.parseResponse(model,response,body,function(err,objects){
cb(null, objects);
})
})
})
else {
console.log(Object.keys(Model))
Model.stream({
limit: req.param('limit') || undefined,
skip: req.param('skip') || req.param('offset') || undefined,
sort: req.param('sort') || req.param('order') || undefined,
where: parseWhereParam(req.params.all()) || undefined
}).pipe(res)
// slow way
// Lookup for records that match the specified criteria
// Model.find({
// limit: req.param('limit') || undefined,
// skip: req.param('skip') || req.param('offset') || undefined,
// sort: req.param('sort') || req.param('order') || undefined,
// where: parseWhereParam(req.params.all()) || undefined
// }).exec(function found(err, matchingRecords) {
// // TODO: differentiate between waterline-originated validation errors
// // and serious underlying issues
// // TODO: Respond with badRequest if an error is encountered, w/ validation info
// if (err) return res.serverError(err);
// // No instances found
// if(!matchingRecords) return res.notFound();
// // // TODO: enable pubsub in blueprints again when new syntax if fully fleshed out
// // req.socket.subscribe(matchingRecords);
// // toJSON() all of the model instances
// matchingRecords = sails.util.invoke(matchingRecords, 'toJSON');
// // Otherwise serve a JSON(P) API
// if ( isJSONPCompatible ) {
// return res.jsonp(matchingRecords);
// }
// else {
// return res.json(matchingRecords);
// }
// });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment