Created
March 11, 2020 13:43
-
-
Save bweave/3ff909fca4a6dc1db6332ecd86aa677d to your computer and use it in GitHub Desktop.
Attempting to roll some pagination in Amber Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < Granite::Base | |
connection pg | |
table users | |
column id : Int64, primary: true | |
column email : String? | |
timestamps | |
end | |
class Pet < Granite::Base | |
connection pg | |
table pets | |
column id : Int64, primary: true | |
column name : String? | |
column breed : String? | |
column age : Int32 | |
timestamps | |
end | |
class Paginator | |
property model : WAT SHOULD THIS BE? | |
def initialize(@model) | |
end | |
def records | |
model.order(id: :asc).limit(10).offset(0) | |
end | |
def pagination | |
Pagination.new | |
end | |
class Pagination | |
# TODO... an object to send messages to like `total_pages`, `total_count`, etc. | |
end | |
end | |
p = Paginator.new(Pet) | |
pets = p.records | |
pagination = p.pagination | |
puts pets.map { |pet| pet.name } | |
p = Paginator.new(User) | |
users = p.records | |
pagination = p.pagination | |
puts users.map { |user| user.email } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment