Skip to content

Instantly share code, notes, and snippets.

@Bodacious
Last active August 14, 2025 09:09
Show Gist options
  • Save Bodacious/bcad497032211e39d374116ed85d2d22 to your computer and use it in GitHub Desktop.
Save Bodacious/bcad497032211e39d374116ed85d2d22 to your computer and use it in GitHub Desktop.
Expressing less-than and greater-than queries in active record with Ruby notation
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'sqlite3'
gem 'activerecord', require: 'active_record'
end
# NOTE: uncomment to show logging
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection({
:adapter => 'sqlite3',
:database =>":memory:",
})
ActiveRecord::Schema.define do
create_table :foobars, force: true do |t|
t.integer :foo
end
end
class Foobar < ActiveRecord::Base
end
puts Foobar.where(foo: ...100).to_sql
puts Foobar.where(foo: ..100).to_sql
puts Foobar.where.not(foo: ..100).to_sql
puts Foobar.where.not(foo: ...100).to_sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment