Module: Sequel::Sequel4DatasetMethods
- Defined in:
- lib/sequel/extensions/sequel_4_dataset_methods.rb
Instance Method Summary collapse
-
#and(*cond, &block) ⇒ Object
Alias for where.
-
#exclude_where(*cond, &block) ⇒ Object
Alias for exclude.
-
#interval(column = (no_arg = true), &block) ⇒ Object
Returns the interval between minimum and maximum values for the given column/expression.
-
#range(column = (no_arg = true), &block) ⇒ Object
Returns a
Range
instance made from the minimum and maximum values for the given column/expression.
Instance Method Details
#and(*cond, &block) ⇒ Object
Alias for where.
28 29 30 |
# File 'lib/sequel/extensions/sequel_4_dataset_methods.rb', line 28 def and(*cond, &block) where(*cond, &block) end |
#exclude_where(*cond, &block) ⇒ Object
Alias for exclude.
33 34 35 |
# File 'lib/sequel/extensions/sequel_4_dataset_methods.rb', line 33 def exclude_where(*cond, &block) exclude(*cond, &block) end |
#interval(column = (no_arg = true), &block) ⇒ Object
Returns the interval between minimum and maximum values for the given column/expression. Uses a virtual row block if no argument is given.
DB[:table].interval(:id) # SELECT (max(id) - min(id)) FROM table LIMIT 1
# => 6
DB[:table].interval{function(column)} # SELECT (max(function(column)) - min(function(column))) FROM table LIMIT 1
# => 7
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sequel/extensions/sequel_4_dataset_methods.rb', line 44 def interval(column=(no_arg = true), &block) column = Sequel.virtual_row(&block) if no_arg if loader = cached_placeholder_literalizer(:_interval_loader) do |pl| arg = pl.arg aggregate_dataset.limit(1).select((SQL::Function.new(:max, arg) - SQL::Function.new(:min, arg)).as(:interval)) end loader.get(column) else aggregate_dataset.get{(max(column) - min(column)).as(:interval)} end end |
#range(column = (no_arg = true), &block) ⇒ Object
Returns a Range
instance made from the minimum and maximum values for the given column/expression. Uses a virtual row block if no argument is given.
DB[:table].range(:id) # SELECT max(id) AS v1, min(id) AS v2 FROM table LIMIT 1
# => 1..10
DB[:table].interval{function(column)} # SELECT max(function(column)) AS v1, min(function(column)) AS v2 FROM table LIMIT 1
# => 0..7
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sequel/extensions/sequel_4_dataset_methods.rb', line 64 def range(column=(no_arg = true), &block) column = Sequel.virtual_row(&block) if no_arg r = if loader = cached_placeholder_literalizer(:_range_loader) do |pl| arg = pl.arg aggregate_dataset.limit(1).select(SQL::Function.new(:min, arg).as(:v1), SQL::Function.new(:max, arg).as(:v2)) end loader.first(column) else aggregate_dataset.select{[min(column).as(v1), max(column).as(v2)]}.first end if r (r[:v1]..r[:v2]) end end |