Created
November 18, 2016 22:44
-
-
Save xfalcox/5639a9b4e7014d0e8c5f1074d161668e to your computer and use it in GitHub Desktop.
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
#antes use gem install sqlite3 sequel | |
require 'sequel' | |
DB = Sequel.connect('sqlite://blog.db') # requires sqlite3 | |
DB.create_table :items do | |
primary_key :id | |
String :name | |
Float :price | |
end | |
items = DB[:items] # Create a dataset | |
# 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