Created
December 3, 2011 02:18
-
-
Save fteem/1425776 to your computer and use it in GitHub Desktop.
a gist of sequel
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
require "rubygems" | |
require "sequel" | |
# connect to an in-memory database | |
DB = Sequel.sqlite | |
# create an items table | |
DB.create_table :items do | |
primary_key :id | |
String :name | |
Float :price | |
end | |
# create a dataset from the items table | |
items = DB[:items] | |
# populate the table | |
items.insert(:name => 'abc', :price => rand * 100) | |
items.insert(:name => 'def', :price => rand * 100) | |
items.insert(:name => 'ghi', :price => rand * 100) | |
# print out the number of records | |
puts "Item count: #{items.count}" | |
# print out the average price | |
puts "The average price is: #{items.avg(:price)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment