Module: Sequel::SQL::ComplexExpressionMethods

Included in:
LiteralString, GenericExpression, Symbol
Defined in:
lib/sequel/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

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.



340
341
342
# File 'lib/sequel/sql.rb', line 340

def extract(datetime_part)
  Function.new(:extract, PlaceholderLiteralString.new("#{datetime_part} FROM ?", [self])).sql_number
end

#sql_booleanObject

Return a BooleanExpression representation of self.



345
346
347
# File 'lib/sequel/sql.rb', line 345

def sql_boolean
  BooleanExpression.new(:NOOP, self)
end

#sql_numberObject

Return a NumericExpression representation of self.



350
351
352
# File 'lib/sequel/sql.rb', line 350

def sql_number
  NumericExpression.new(:NOOP, self)
end

#sql_stringObject

Return a StringExpression representation of self.



355
356
357
# File 'lib/sequel/sql.rb', line 355

def sql_string
  StringExpression.new(:NOOP, self)
end