Sha256: 90666d6c0637deaaa4b269732ac7fca124e6bdeef2860b676bd8b67dcd2efa55

Contents?: true

Size: 1.59 KB

Versions: 23

Compression:

Stored size: 1.59 KB

Contents

# frozen-string-literal: true
#
# The filter_having extension allows Dataset#filter, #and, #or
# and #exclude to operate on the HAVING clause if the dataset
# already has a HAVING clause, which was the historical behavior
# before Sequel 4.  It is only recommended to use this for
# backwards compatibility.
#
# You can load this extension into specific datasets:
#
#   ds = DB[:table]
#   ds = ds.extension(:filter_having)
#
# Or you can load it into all of a database's datasets, which
# is probably the desired behavior if you are using this extension:
#
#   DB.extension(:filter_having)
#
# Related module: Sequel::FilterHaving

#
module Sequel
  module FilterHaving
    # Operate on HAVING clause if HAVING clause already present.
    def and(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def exclude(*cond, &block)
      if @opts[:having]
        exclude_having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def filter(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def or(*cond, &block)
      if having = @opts[:having]
        cond = cond.first if cond.size == 1
        clone(:having => SQL::BooleanExpression.new(:OR, having, filter_expr(cond, &block)))
      else
        super
      end
    end
  end

  Dataset.register_extension(:filter_having, FilterHaving)
end

Version data entries

23 entries across 21 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/sequel-4.44.0/lib/sequel/extensions/filter_having.rb
tdiary-5.0.5 vendor/bundle/gems/sequel-4.44.0/lib/sequel/extensions/filter_having.rb
tdiary-5.0.5 vendor/bundle/gems/sequel-4.47.0/lib/sequel/extensions/filter_having.rb
sequel-4.47.0 lib/sequel/extensions/filter_having.rb
sequel-4.46.0 lib/sequel/extensions/filter_having.rb
sequel-4.45.0 lib/sequel/extensions/filter_having.rb
tdiary-5.0.4 vendor/bundle/gems/sequel-4.44.0/lib/sequel/extensions/filter_having.rb
sequel-4.44.0 lib/sequel/extensions/filter_having.rb
sequel-4.43.0 lib/sequel/extensions/filter_having.rb
sequel-4.42.1 lib/sequel/extensions/filter_having.rb
sequel-4.42.0 lib/sequel/extensions/filter_having.rb
sequel-4.41.0 lib/sequel/extensions/filter_having.rb
sequel-4.40.0 lib/sequel/extensions/filter_having.rb
sequel-4.39.0 lib/sequel/extensions/filter_having.rb
tdiary-5.0.2 vendor/bundle/gems/sequel-4.37.0/lib/sequel/extensions/filter_having.rb
sequel-4.38.0 lib/sequel/extensions/filter_having.rb
sequel-4.37.0 lib/sequel/extensions/filter_having.rb
sequel-4.36.0 lib/sequel/extensions/filter_having.rb
tdiary-5.0.1 vendor/bundle/gems/sequel-4.35.0/lib/sequel/extensions/filter_having.rb
sequel-4.35.0 lib/sequel/extensions/filter_having.rb