Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
example of using the ruby sequel gem to access a sqlite3 database on jruby
#############################################################################
# to use this in jruby:
#
# jgem install sequel
# jgem install jdbc-sqlite3
#
# for more info on the sequel library, go to http://sequel.rubyforge.org/
#############################################################################
require 'rubygems'
require 'sequel'
DB = Sequel.connect('jdbc:sqlite:db.sqlite3')
unless DB.table_exists?(:items)
DB.create_table :items do
column :name, :text
column :price, :float
end
end
items = DB[:items]
items << {:name => 'abc', :price => rand * 100}
items << {:name => 'def', :price => rand * 100}
items << {:name => 'ghi', :price => rand * 100}
puts "Item Count = #{items.count}"
items.reverse_order(:price).each do |item|
p item
end
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
You can’t perform that action at this time.