Created
July 6, 2009 05:35
-
-
Save softprops/141274 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
%w(rufus/tokyo pp ftools time).each { |l| require l } | |
file = 'data.tct' | |
FileUtils.rm file | |
db = Rufus::Tokyo::Table.new(file) | |
date_col = 'created_at' | |
data = { | |
db.genuid => 'fri jul 03 18:53:24 -0400 2009', | |
db.genuid => 'sat jul 04 01:51:30 -0400 2009', | |
db.genuid => 'mon jul 06 00:20:30 -0400 2009', | |
} | |
data.each_pair { |id, date| db[id.to_s] = { date_col => date } } | |
# expect 1,2,3 returns 1,3,2 | |
pp db.query { |q| q.order_by date_col, :asc } | |
# expect 3,2,1 returns 2,3,1 | |
pp db.query { |q| q.order_by date_col, :desc } | |
# note that :asc and :desc refer to | |
# string ordering => http://github.com/jmettraux/rufus-tokyo/blob/92f66d26d22f50e03d4f286c3592d874646dc11b/lib/rufus/tokyo/cabinet/table.rb#L596-609 | |
db.close | |
FileUtils.rm file | |
db = Rufus::Tokyo::Table.new(file) | |
data = { | |
db.genuid => Time.parse('fri jul 03 18:53:24 -0400 2009'), | |
db.genuid => Time.parse('sat jul 04 01:51:30 -0400 2009'), | |
db.genuid => Time.parse('mon jul 06 00:20:30 -0400 2009'), | |
} | |
data.each_pair { |id, date| db[id.to_s] = { date_col => date.to_i.to_s } } | |
# expect 1,2,3 returns 1,2,3 | |
pp db.query { |q| q.order_by date_col, :numasc } # :asc works as well | |
# expect 3,2,1 returns 3,2,1 | |
pp db.query { |q| q.order_by date_col, :numdesc } # :desc works as well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment