Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequel scope all with default scope bench #79

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions sequel/benchmarks/bm_sequel_scope_all_with_default_scope.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'bundler/setup'
require 'sequel'

require_relative 'support/benchmark_sequel'

DB = Sequel.connect(ENV.fetch('DATABASE_URL'))

DB.create_table!(:users) do
primary_key :id
String :name, size: 255
String :email, size: 255
TrueClass :admin, null: false
DateTime :created_at, null: true
DateTime :updated_at, null: true
end

class User < Sequel::Model
dataset_module do
def only_admins
where(:admin => true)
end
end

set_dataset(self.only_admins)
end

admin = true

1000.times do
attributes = {
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
email: "foobar@email.com",
admin: admin
}

User.create(attributes)

admin = !admin
end

Benchmark.sequel("sequel/#{db_adapter}_scope_all_with_default_scope", time: 5) do
str = ""
User.all.each do |user|
str << "name: #{user.name} email: #{user.email}\n"
end
end