module Sequel::Sequel4DatasetMethods

Public Instance Methods

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

Alias for where.

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

Alias for exclude.

   # File lib/sequel/extensions/sequel_4_dataset_methods.rb
33 def exclude_where(*cond, &block)
34   exclude(*cond, &block)
35 end
interval(column=Sequel.virtual_row(&Proc.new)) click to toggle source

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

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