views:

59

answers:

1

Hi, I've just installed "sequel" gem for Ruby. I wanted to try example from Sequel website and it won't work :( test.rb:

require 'rubygems'
require 'sequel'

DB = Sequel.sqlite # memory database

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)}"

Console:

$ sequel test.rb
Error: ArgumentError: syntax error on line 11, col 37: `i'/usr/lib/ruby/1.8/yaml.rb:133:in `load'
+2  A: 

You need to run this with ruby not sequel

$ ruby test.rb
bjg
No, no. It outputs even more errors. That's not it :(
dmitq
+1 because this should work, if not, there is something wrong with your ruby or sequel installation. What are the errors for `ruby test.rb`?
jigfox
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': LoadError: no such file to load -- sqlite3 (Sequel::AdapterNotFound) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/sqlite.rb:1 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `k_require'(and more...)I have installed sequel by "gem install sequel". Ramaze works fine.
dmitq
You need to install sqlite3 as well.
Mladen Jablanović
Technically, you need the sqlite3-ruby gem: "sudo gem install sqlite3-ruby"
Jeremy Evans