Module: Sequel::SQL::ComplexExpressionMethods

Included in:
Dataset, LiteralString, GenericExpression, Symbol
Defined in:
lib/sequel/sql.rb

Overview

Adds methods that allow you to treat an object as an instance of a specific ComplexExpression subclass. This is useful if another library overrides the methods defined by Sequel.

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) # extract(year FROM "date")

Also has the benefit of returning the result as a NumericExpression instead of a generic ComplexExpression.



747
748
749
# File 'lib/sequel/sql.rb', line 747

def extract(datetime_part)
  NumericExpression.new(:extract, datetime_part, self)
end

#sql_booleanObject

Return a BooleanExpression representation of self.



752
753
754
# File 'lib/sequel/sql.rb', line 752

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

#sql_numberObject

Return a NumericExpression representation of self.

~:a # NOT "a"
~:a.sql_number # ~"a"


760
761
762
# File 'lib/sequel/sql.rb', line 760

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

#sql_stringObject

Return a StringExpression representation of self.

:a + :b # "a" + "b"
:a.sql_string + :b # "a" || "b"


768
769
770
# File 'lib/sequel/sql.rb', line 768

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