Class | Sequel::SQL::DateAdd |
In: |
lib/sequel/extensions/date_arithmetic.rb
|
Parent: | GenericExpression |
The DateAdd class represents the addition of an interval to a date/timestamp expression.
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. |
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, line 187 187: def initialize(expr, interval, opts=OPTS) 188: @expr = expr 189: @interval = if interval.is_a?(Hash) 190: interval.each_value do |v| 191: # Attempt to prevent SQL injection by users who pass untrusted strings 192: # as interval values. 193: if v.is_a?(String) && !v.is_a?(LiteralString) 194: raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}" 195: end 196: end 197: Hash[interval] 198: else 199: h = Hash.new(0) 200: interval.parts.each{|unit, value| h[unit] += value} 201: Hash[h] 202: end 203: 204: @interval.freeze 205: @cast_type = opts[:cast] if opts[:cast] 206: freeze 207: end