I have this code:
require 'bundler/setup'
require 'sequel'
require 'sequel-rails'
require_relative 'support/benchmark_rails'
DB = Sequel.connect('sqlite::memory:')
COUNT=25
Sequel.extension :migration
Sequel.migration do
change do
create_table(:users) do
primary_key :id
COUNT.times do |i|
column :"column#{i}", "varchar(255)"
end
end
end
end
class User < Sequel::Model; end
attributes = {}
COUNT.times do |i|
attributes[:"column#{i}"] = "Some string #{i}"
end
Benchmark.rails("sequel/#{db_adapter}_create_string_columns", time: 5) do
User.create(attributes)
end
But when I try to run this, it gives the following error:
/home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:1759:in `block in set_restricted': method name= doesn't exist (Sequel::Error)
from /home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:1746:in `each'
from /home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:1746:in `set_restricted'
from /home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:1257:in `set'
from /home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:1715:in `initialize_set'
from /home/aaditya/Downloads/ruby-bench-suite/rails/vendor/bundle/ruby/2.3.0/gems/sequel-3.40.0/lib/sequel/model/base.rb:899:in `initialize'
from benchmarks/bm_sequel_create_string_columns.rb:34:in `new'
from benchmarks/bm_sequel_create_string_columns.rb:34:in `<main>'
I tried to simplify this and tried to run only User.create(:name=>'Bob')
but with no successful results. What mistake am I making?
There are no problems with the other methods as the same code is running for Active Record.
You are just defining the migration, you aren't actually running the CREATE TABLE
on the database. Remove the migration code and just call DB.create_table
.