Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
component {
remote function getData(numeric page=1) {
var start = (arguments.page-1)*10+1;
if(start < 1 || round(start) neq start) start=1;
//force json
url.returnformat="json";
var q = new query();
q.setDatasource("blog");
q.setSQL("select title from tblblogentries limit #start-1#,10");
var queryResult = q.execute().getResult();
var result = {"total"=getTotal(),"titles"=[]};
for(var i=1; i<queryResult.recordCount; i++) arrayAppend(result.titles, queryResult.title[i]);
return result;
}
private function getTotal() {
var total = cacheGet("total");
if(isNull(total)) {
var q = new query();
q.setDatasource("blog");
q.setSQL("select count(0) as total from tblblogentries");
var total = q.execute().getResult().total;
cachePut("total", total);
}
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment