Module: Sequel::SQL::ComplexExpressionMethods
- Includes:
- BooleanMethods, InequalityMethods, NumericMethods, StringMethods
- Included in:
- LiteralString, GenericExpressionMethods
- Defined in:
- lib/sequel_core/sql.rb
Overview
This module includes other Sequel::SQL::*Methods modules and is included in other classes that are could be either booleans, strings, or numbers. It also adds three methods so that can specify behavior in case one of the operator methods has been overridden (such as Symbol#/).
For example, if Symbol#/ is overridden to produce a string (for example, to make file system path creation easier), the following code will not do what you want:
:price/10 > 100
In that case, you need to do the following:
:price.sql_number/10 > 100
Instance Method Summary collapse
-
#extract(datetime_part) ⇒ Object
Extract a datetime_part (e.g. year, month) from self:.
-
#sql_boolean ⇒ Object
Return a BooleanExpression representation of self.
-
#sql_number ⇒ Object
Return a NumericExpression representation of self.
-
#sql_string ⇒ Object
Return a StringExpression representation of self.
Methods included from StringMethods
Methods included from BooleanMethods
Instance Method Details
#extract(datetime_part) ⇒ Object
Extract a datetime_part (e.g. year, month) from self:
:date.extract(:year) # SQL: extract(year FROM date)
Also has the benefit of returning the result as a NumericExpression instead of a generic ComplexExpression.
346 347 348 |
# File 'lib/sequel_core/sql.rb', line 346 def extract(datetime_part) IrregularFunction.new(:extract, datetime_part.to_s.lit, :FROM, self).sql_number end |
#sql_boolean ⇒ Object
Return a BooleanExpression representation of self.
351 352 353 |
# File 'lib/sequel_core/sql.rb', line 351 def sql_boolean BooleanExpression.new(:NOOP, self) end |
#sql_number ⇒ Object
Return a NumericExpression representation of self.
356 357 358 |
# File 'lib/sequel_core/sql.rb', line 356 def sql_number NumericExpression.new(:NOOP, self) end |
#sql_string ⇒ Object
Return a StringExpression representation of self.
361 362 363 |
# File 'lib/sequel_core/sql.rb', line 361 def sql_string StringExpression.new(:NOOP, self) end |