module Sequel::Sequel4DatasetMethods

  1. lib/sequel/extensions/sequel_4_dataset_methods.rb

Methods

Public Instance

  1. and
  2. exclude_where
  3. interval
  4. range

Public Instance methods

and(*cond, &block)

Alias for where.

[show source]
   # File lib/sequel/extensions/sequel_4_dataset_methods.rb
28 def and(*cond, &block)
29   where(*cond, &block)
30 end
exclude_where(*cond, &block)

Alias for exclude.

[show source]
   # File lib/sequel/extensions/sequel_4_dataset_methods.rb
33 def exclude_where(*cond, &block)
34   exclude(*cond, &block)
35 end
interval(column=(no_arg = true), &block)

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
[show source]
   # File lib/sequel/extensions/sequel_4_dataset_methods.rb
44 def interval(column=(no_arg = true), &block)
45   column = Sequel.virtual_row(&block) if no_arg
46   if loader = cached_placeholder_literalizer(:_interval_loader) do |pl|
47       arg = pl.arg
48       aggregate_dataset.limit(1).select((SQL::Function.new(:max, arg) - SQL::Function.new(:min, arg)).as(:interval))
49     end
50 
51     loader.get(column)
52   else
53     aggregate_dataset.get{(max(column) - min(column)).as(:interval)}
54   end
55 end
range(column=(no_arg = true), &block)

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
[show source]
   # File lib/sequel/extensions/sequel_4_dataset_methods.rb
64 def range(column=(no_arg = true), &block)
65   column = Sequel.virtual_row(&block) if no_arg
66   r = if loader = cached_placeholder_literalizer(:_range_loader) do |pl|
67         arg = pl.arg
68         aggregate_dataset.limit(1).select(SQL::Function.new(:min, arg).as(:v1), SQL::Function.new(:max, arg).as(:v2))
69       end
70 
71     loader.first(column)
72   else
73     aggregate_dataset.select{[min(column).as(v1), max(column).as(v2)]}.first
74   end
75 
76   if r
77     (r[:v1]..r[:v2])
78   end
79 end