PgORM::PaginatedResult(T)
Inherits Struct < Value < Object
Result wrapper for offset-based pagination containing records and metadata.
Records are loaded lazily - the database query doesn't execute until you access the records. This allows you to pass pagination results around without loading data unnecessarily.
Metadata Available
total: Total number of records matching the querylimit: Number of records per pageoffset: Number of records skippedpage: Current page number (1-indexed)total_pages: Total number of pageshas_next?: Whether there's a next pagehas_prev?: Whether there's a previous pagenext_page: Next page number (or nil)prev_page: Previous page number (or nil)from: Starting record number (1-indexed)to: Ending record number (1-indexed)
Example
result = User.where(active: true).paginate(page: 2, limit: 20)
result.total # => 150
result.page # => 2
result.total_pages # => 8
result.has_next? # => true
result.from # => 21
result.to # => 40
# Records loaded only when accessed
result.records.each do |user|
puts user.name
end
# Or iterate directly
result.each do |user|
puts user.name
end
Constructors
new(query : Collection(T) | Relation(T), total : Int64, limit : Int32, offset : Int32)
SourceInstance methods
each
Iterate over records without loading all into memory at once This allows streaming/processing records one at a time
limit
Sourceoffset
Sourcepage
Sourcerecords
Lazily load records only when accessed Records are cached after first access to avoid multiple DB queries
to_json(json : JSON::Builder)
Convert to JSON with pagination metadata Note: This will load all records into memory for serialization
total
Source