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.

Instance Method Summary collapse

Instance Method Details

#extract(datetime_part) ⇒ Object

Extract a datetime part (e.g. year, month) from self:

Sequel[:date].extract(:year) # extract(year FROM "date")

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



726
727
728
# File 'lib/sequel/sql.rb', line 726

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

#sql_booleanObject

Return a BooleanExpression representation of self.



731
732
733
# File 'lib/sequel/sql.rb', line 731

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

#sql_numberObject

Return a NumericExpression representation of self.

~Sequel[:a] # NOT "a"
~(Sequel[:a].sql_number) # ~"a"


739
740
741
# File 'lib/sequel/sql.rb', line 739

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

#sql_stringObject

Return a StringExpression representation of self.

Sequel[:a] + :b # "a" + "b"
Sequel[:a].sql_string + :b # "a" || "b"


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

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