仔细查看Github上的代码,我想我找到了答案。它将使用返回记录计数的数据库查询计数方法。以下是使用查询计数分页记录的示例:
db = Rufus::Tokyo::Table.new(@file)
begin
# Need to find the total number of records that would be returned.
# could use db#size, except that our query filters out records after today.
total_count = db.query_count { |q|
q.add_condition 'date', :numle, @today
q.order_by 'date', :strdesc
}
pager = IndexCards::Pager.new requested_page_num, total_count
# Now let's pull the slice that we want.
results = db.query { |q|
q.add_condition 'date', :numle, @today
q.order_by 'date', :strdesc
q.limit(pager.limit, pager.offset)
}
ensure
db.close
end