public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# AR & Sequel
User.where(name: "Tom")
User.where("name = :name", name: "Tom")
User.where("name = ? OR email = ?", "Tom", "jack@jack.com")
User.where("users.name = ?", "Tom")
 
# AR-only
User.where(users: { name: "Tom" })
# Sequel-only
User.where(users__name: "Tom")
User.where(Sequel.lit('users.name') => "Tom")
 
# Sequel alternative option for "name = ? OR email = ?"
User.where(Sequel.expr(name: "Tom") | Sequel.expr(email: "jack@jack.com"))
# Sequel alternative option for "name = ? OR email != ?" / "name = ? OR NOT (email = ?)"
User.where(Sequel.expr(name: "Tom") | Sequel.~(email: "jack@jack.com"))
 
# AR-only
User.select("SUM(id)").first
# Sequel-only
User.select(Sequel.function(:sum, :id)).first
 
# AR-only (4.x)
User.where.not(name: "Tom")
# Sequel-only
User.exclude(name: "Tom")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.