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.



704
705
706
# File 'lib/sequel/sql.rb', line 704

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

#sql_booleanObject

Return a BooleanExpression representation of self.



709
710
711
# File 'lib/sequel/sql.rb', line 709

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"


717
718
719
# File 'lib/sequel/sql.rb', line 717

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"


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

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