Skip to content

Instantly share code, notes, and snippets.

@pjambet
Created February 25, 2014 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjambet/9200139 to your computer and use it in GitHub Desktop.
Save pjambet/9200139 to your computer and use it in GitHub Desktop.
var getAllObjects = function(className, options) {
var batchSize = 100;
var grandResult = [];
var offset = 0;
var getNextBatch = function(objects) {
if (objects) {
grandResult = grandResult.concat(objects);
}
if (objects === null || objects.length === batchSize) {
var query = new Parse.Query(className);
query.limit(100);
if (objects) {
offset += batchSize;
}
query.skip(offset);
query.ascending('createdAt');
if (options) {
_.each(options, function(optionArgs, optionLabel) {
query[optionLabel].apply(query, optionArgs);
});
}
return query.find().then(getNextBatch);
} else {
return Parse.Promise.as(grandResult);
}
};
return getNextBatch(null);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment