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.



729
730
731
# File 'lib/sequel/sql.rb', line 729

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

#sql_booleanObject

Return a BooleanExpression representation of self.



734
735
736
# File 'lib/sequel/sql.rb', line 734

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"


742
743
744
# File 'lib/sequel/sql.rb', line 742

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"


750
751
752
# File 'lib/sequel/sql.rb', line 750

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