Module: Sequel::SQL::ComplexExpressionMethods
- Included in:
- 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
-
#extract(datetime_part) ⇒ Object
Extract a datetime_part (e.g. year, month) from self:.
-
#sql_boolean ⇒ Object
Return a BooleanExpression representation of self.
-
#sql_number ⇒ Object
Return a NumericExpression representation of self.
-
#sql_string ⇒ Object
Return a StringExpression representation of self.
Instance Method Details
#extract(datetime_part) ⇒ Object
Extract a datetime_part (e.g. year, month) from self:
:date.extract(:year) # SQL: extract(year FROM "date")
Also has the benefit of returning the result as a NumericExpression instead of a generic ComplexExpression.
The extract function is in the SQL standard, but it doesn’t doesn’t use the standard function calling convention.
220 221 222 |
# File 'lib/sequel/sql.rb', line 220 def extract(datetime_part) Function.new(:extract, PlaceholderLiteralString.new("#{datetime_part} FROM ?", [self])).sql_number end |
#sql_boolean ⇒ Object
Return a BooleanExpression representation of self.
225 226 227 |
# File 'lib/sequel/sql.rb', line 225 def sql_boolean BooleanExpression.new(:NOOP, self) end |
#sql_number ⇒ Object
Return a NumericExpression representation of self.
230 231 232 |
# File 'lib/sequel/sql.rb', line 230 def sql_number NumericExpression.new(:NOOP, self) end |
#sql_string ⇒ Object
Return a StringExpression representation of self.
235 236 237 |
# File 'lib/sequel/sql.rb', line 235 def sql_string StringExpression.new(:NOOP, self) end |