module Sequel::ExcludeOrNull

Public Instance Methods

exclude_or_null(*cond, &block) click to toggle source

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)
   # File lib/sequel/extensions/exclude_or_null.rb
41 def exclude_or_null(*cond, &block)
42   add_filter(:where, cond, :or_null, &block)
43 end
exclude_or_null_having(*cond, &block) click to toggle source

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)
   # File lib/sequel/extensions/exclude_or_null.rb
50 def exclude_or_null_having(*cond, &block)
51   add_filter(:having, cond, :or_null, &block)
52 end

Private Instance Methods

_invert_filter(cond, invert) click to toggle source

Recognize :or_null value for invert, returning an expression for the invert of the condition or the condition being null.

Calls superclass method
   # File lib/sequel/extensions/exclude_or_null.rb
58 def _invert_filter(cond, invert)
59   if invert == :or_null
60     ~SQL::Function.new(:coalesce, cond, SQL::Constants::SQLFALSE)
61   else
62     super
63   end
64 end