The query expression includes an orderBy
function.
let c = Customer[true].orderBy('name') //sort by name ascending
let c2 = Customer[true].orderBy('name', asc) //the same thing
let c3 = Customer[name == 'smith'].orderBy('id', desc) //sort by id descending
The query expression includes a limit
and offset
functions to get a portion of the matching records.
The offset
function takes a 0-based integer that is the index of the matching records.
The limit
function takes a integer that is the number of the matching records to get.
let c = Customer[true].offset(100).limit(25)
If you wanted to get pages of 4 records and there are 12 records:
let page1 = Customer[true].offset(0).limit(4) //get rows 0..3
let page2 = Customer[true].offset(4).limit(4) //get rows 4..7
let page3 = Customer[true].offset(8).limit(4) //get rows 8..11