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.
339 340 341 |
# File 'lib/sequel_core/sql.rb', line 339 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.
344 345 346 |
# File 'lib/sequel_core/sql.rb', line 344 def sql_boolean BooleanExpression.new(:NOOP, self) end |
#sql_number ⇒ Object
Return a NumericExpression representation of self.
349 350 351 |
# File 'lib/sequel_core/sql.rb', line 349 def sql_number NumericExpression.new(:NOOP, self) end |
#sql_string ⇒ Object
Return a StringExpression representation of self.
354 355 356 |
# File 'lib/sequel_core/sql.rb', line 354 def sql_string StringExpression.new(:NOOP, self) end |