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
186 def initialize(expr, interval, opts=OPTS)
187   @expr = expr
188   @interval = if interval.is_a?(Hash)
189     interval.each_value do |v|
190        # Attempt to prevent SQL injection by users who pass untrusted strings
191        # as interval values.
192        if v.is_a?(String) && !v.is_a?(LiteralString)
193          raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}"
194        end
195     end
196     Hash[interval]
197   else
198     h = Hash.new(0)
199     interval.parts.each{|unit, value| h[unit] += value}
200     Hash[h]
201   end
202 
203   @interval.freeze
204   @cast_type = opts[:cast] if opts[:cast]
205   freeze
206 end