module Sequel::SQL::ComplexExpressionMethods

  1. lib/sequel/sql.rb
Parent: SQL

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

Methods

Public Instance

  1. extract
  2. sql_boolean
  3. sql_number
  4. sql_string

Public Instance methods

extract (datetime_part)

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.

[show source]
# File lib/sequel/sql.rb, line 710
def extract(datetime_part)
  NumericExpression.new(:extract, datetime_part, self)
end
sql_boolean ()

Return a BooleanExpression representation of self.

[show source]
# File lib/sequel/sql.rb, line 715
def sql_boolean
  BooleanExpression.new(:NOOP, self)
end
sql_number ()

Return a NumericExpression representation of self.

~:a # NOT "a"
~:a.sql_number # ~"a"
[show source]
# File lib/sequel/sql.rb, line 723
def sql_number
  NumericExpression.new(:NOOP, self)
end
sql_string ()

Return a StringExpression representation of self.

:a + :b # "a" + "b"
:a.sql_string + :b # "a" || "b"
[show source]
# File lib/sequel/sql.rb, line 731
def sql_string
  StringExpression.new(:NOOP, self)
end