Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Created Mar 19, 2009
Embed
What would you like to do?
(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