Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created December 18, 2012 13:07
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 cfjedimaster/4327849 to your computer and use it in GitHub Desktop.
Save cfjedimaster/4327849 to your computer and use it in GitHub Desktop.
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