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

Methods included from StringMethods

#ilike, #like

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.



338
339
340
# File 'lib/sequel_core/sql.rb', line 338

def extract(datetime_part)
  IrregularFunction.new(:extract, datetime_part.to_s.lit, :FROM, self).sql_number
end

#sql_booleanObject

Return a BooleanExpression representation of self.



343
344
345
# File 'lib/sequel_core/sql.rb', line 343

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

#sql_numberObject

Return a NumericExpression representation of self.



348
349
350
# File 'lib/sequel_core/sql.rb', line 348

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

#sql_stringObject

Return a StringExpression representation of self.



353
354
355
# File 'lib/sequel_core/sql.rb', line 353

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