Class: Sequel::SQL::DateAdd
- Inherits:
-
GenericExpression
- Object
- Expression
- GenericExpression
- Sequel::SQL::DateAdd
- Defined in:
- lib/sequel/extensions/date_arithmetic.rb
Overview
The DateAdd class represents the addition of an interval to a date/timestamp expression.
Defined Under Namespace
Modules: DatasetMethods
Instance Attribute Summary collapse
-
#expr ⇒ Object
readonly
The expression that the interval is being added to.
-
#interval ⇒ Object
readonly
The interval added to the expression, as a hash with symbol keys.
Instance Method Summary collapse
-
#initialize(expr, interval) ⇒ DateAdd
constructor
- Supports two types of intervals: Hash
-
Used directly, but values cannot be plain strings.
Methods included from Postgres::HStoreOpMethods
Methods included from Postgres::RangeOpMethods
Methods included from Postgres::ArrayOpMethods
Methods included from Postgres::JSONOpMethods
Methods included from Postgres::InetOpMethods
Methods included from Postgres::PGRowOp::ExpressionMethods
Methods included from SubscriptMethods
Methods included from StringMethods
Methods included from PatternMatchMethods
Methods included from OrderMethods
Methods included from NumericMethods
Methods included from ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from CastMethods
#cast, #cast_numeric, #cast_string
Methods included from BooleanMethods
Methods included from AliasMethods
Methods inherited from Expression
#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal
Constructor Details
#initialize(expr, interval) ⇒ DateAdd
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.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/sequel/extensions/date_arithmetic.rb', line 172 def initialize(expr, interval) @expr = expr @interval = if interval.is_a?(Hash) interval.each_value do |v| # Attempt to prevent SQL injection by users who pass untrusted strings # as interval values. if v.is_a?(String) && !v.is_a?(LiteralString) raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}" end end interval else h = Hash.new(0) interval.parts.each{|unit, value| h[unit] += value} Hash[h] end end |
Instance Attribute Details
#expr ⇒ Object (readonly)
The expression that the interval is being added to.
163 164 165 |
# File 'lib/sequel/extensions/date_arithmetic.rb', line 163 def expr @expr end |
#interval ⇒ Object (readonly)
The interval added to the expression, as a hash with symbol keys.
167 168 169 |
# File 'lib/sequel/extensions/date_arithmetic.rb', line 167 def interval @interval end |