- Function ahead of codes of dao in Python
def _find(query):
result = []
count = query.count()
pages = count/1000 + 1
print count
for i in range(pages):
_query = copy.deepcopy(query)
_query.limit(1000)
_query.skip(i * 1000)
res = _query.find()
for item in res:
result.append(item)
return result
- Demo
from leancloud import Query, Object
UserSenz = Object.extend("UserSenz")
User = Object.extend("User")
query = Query(UserSenz)
user = User()
user.id = user_id
query.equal_to("user", user)
query.greater_than("timestamp", start_time)
query.less_than("timestamp", end_time)
query.ascending("timestamp")
behavior = _find(query)
- Function ahead of codes of dao in NodeJS
var _findAll = function (query){
return query.count().then(
function (count){
var promises = [];
var pages = Math.ceil(count/1000);
for (var i = 0; i <= pages; i ++){
var _query = _.clone(query);
_query.limit(1000);
_query.skip(i*1000);
promises.push(_query.find());
}
return AV.Promise.all(promises);
},
function (error){
return AV.Promise.error(error);
}
).then(
function (results){
var rebuid_result = [];
results.forEach(function (result_list){
result_list.forEach(function (list_item){
rebuid_result.push(list_item);
});
});
return AV.Promise.as(rebuid_result);
},
function (error){
return AV.Promise.error(error);
}
);
};
- Demo
query.ascending("timestamp");
query.limit(1000);
_findAll(query).then(
function (result) {
return AV.Promise.as(result);
},
function (error) {
return AV.Promise.error(error);
}
);
The function is used for querying all data. So there is no need to add addtion limit condition.