Module: Sequel::ExcludeOrNull

Defined in:
lib/sequel/extensions/exclude_or_null.rb

Instance Method Summary collapse

Instance Method Details

#exclude_or_null(*cond, &block) ⇒ Object

Performs the inverse of Dataset#where, but also excludes rows where the given condition IS NULL.

DB[:items].exclude_or_null(category: 'software')
# SELECT * FROM items WHERE NOT coalesce((category = 'software'), false)

DB[:items].exclude_or_null(category: 'software', id: 3)
# SELECT * FROM items WHERE NOT coalesce(((category = 'software') AND (id = 3)), false)


41
42
43
# File 'lib/sequel/extensions/exclude_or_null.rb', line 41

def exclude_or_null(*cond, &block)
  add_filter(:where, cond, :or_null, &block)
end

#exclude_or_null_having(*cond, &block) ⇒ Object

The same as exclude_or_null, but affecting the HAVING clause instead of the WHERE clause.

DB[:items].select_group(:name).exclude_or_null_having{count(name) < 2}
# SELECT name FROM items GROUP BY name HAVING NOT coalesce((count(name) < 2), true)


50
51
52
# File 'lib/sequel/extensions/exclude_or_null.rb', line 50

def exclude_or_null_having(*cond, &block)
  add_filter(:having, cond, :or_null, &block)
end