Created
July 26, 2016 12:38
-
-
Save crisward/7c541376d7a9f4aa40b89d07d64558e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batchFindAll = (model,where,cback,size=10)-> | |
model.count({where}) | |
.then (res)=> | |
total = res | |
[0..Math.floor(total/size)].reduce (curr,num)=> | |
count = num*10 | |
curr.then => cback(where,count,size) | |
,Promise.resolve() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var batchFindAll = function(model,where,cback,size){ | |
var total = 0; | |
var offset = 0; | |
if(size==null) size=10; | |
return model.count({where:where}).then(function(res){ | |
total = res; | |
pages = []; | |
for(var i=0;i<Math.ceil(total/size);i++){ | |
pages.push(i); | |
} | |
return pages.reduce (function(curr,num){ | |
var count = num*10; | |
return curr.then(function(){ return cback(where,count,size);}); | |
},Promise.resolve()); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment