class Sequel::SQL::DateAdd

The DateAdd class represents the addition of an interval to a date/timestamp expression.

Attributes

cast_type[R]

The type to cast the expression to. nil if not overridden, in which cast the generic timestamp type for the database will be used.

expr[R]

The expression that the interval is being added to.

interval[R]

The interval added to the expression, as a hash with symbol keys.

Public Class Methods

new(expr, interval, opts=OPTS) click to toggle source

Supports two types of intervals:

Hash

Used directly, but values cannot be plain strings.

ActiveSupport::Duration

Converted to a hash using the interval's parts.

    # File lib/sequel/extensions/date_arithmetic.rb
190 def initialize(expr, interval, opts=OPTS)
191   @expr = expr
192   @interval = if interval.is_a?(Hash)
193     interval.each_value do |v|
194        # Attempt to prevent SQL injection by users who pass untrusted strings
195        # as interval values.
196        if v.is_a?(String) && !v.is_a?(LiteralString)
197          raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}"
198        end
199     end
200     Hash[interval]
201   else
202     h = Hash.new(0)
203     interval.parts.each{|unit, value| h[unit] += value}
204     Hash[h]
205   end
206 
207   @interval.freeze
208   @cast_type = opts[:cast] if opts[:cast]
209   freeze
210 end