Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Created March 19, 2009 05:21
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 jmettraux/81608 to your computer and use it in GitHub Desktop.
Save jmettraux/81608 to your computer and use it in GitHub Desktop.
(limit only) setlimit(2, 0) --> 2 rows
(limit only) setlimit(2, 1) --> 2 rows
(limit only) setlimit(2, 2) --> 2 rows
(limit only) setlimit(2, 3) --> 2 rows
(limit only) setlimit(2, 4) --> 1 rows
(order and limit) setlimit(2, 0) --> 2 rows
(order and limit) setlimit(2, 1) --> 3 rows
(order and limit) setlimit(2, 2) --> 3 rows
(order and limit) setlimit(2, 3) --> 2 rows
(order and limit) setlimit(2, 4) --> 1 rows
#
# issue with setlimit(max, skip)
#
#
# sudo gem install rufus-tokyo
#
require 'rubygems'
require 'rufus/tokyo'
t = Rufus::Tokyo::Table.new('table.tct')
t['pk0'] = { 'name' => 'alfred', 'age' => '22' }
t['pk1'] = { 'name' => 'bob', 'age' => '18' }
t['pk2'] = { 'name' => 'charly', 'age' => '45' }
t['pk3'] = { 'name' => 'doug', 'age' => '77' }
t['pk4'] = { 'name' => 'ephrem', 'age' => '32' }
MAX = 2
puts
5.times do |i|
count = t.query { |q| q.limit MAX, i }.size
puts " (limit only) setlimit(#{MAX}, #{i}) --> #{count} rows"
end
puts
5.times do |i|
count = t.query { |q|
q.order_by 'name', :desc
q.limit MAX, i
}.size
puts " (order and limit) setlimit(#{MAX}, #{i}) --> #{count} rows"
end
t.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment