Module: Sequel::SQL::CastMethods

Included in:
ComplexExpression, GenericExpression, String, Symbol
Defined in:
lib/sequel_core/sql.rb

Overview

Holds methods that are used to cast objects to differen SQL types.

Instance Method Summary collapse

Instance Method Details

#cast(sql_type) ⇒ Object Also known as: cast_as

Cast the reciever to the given SQL type



183
184
185
# File 'lib/sequel_core/sql.rb', line 183

def cast(sql_type)
  Cast.new(self, sql_type)
end

#cast_numeric(sql_type = nil) ⇒ Object

Cast the reciever to the given SQL type (or integer if none given), and return the result as a NumericExpression.



190
191
192
# File 'lib/sequel_core/sql.rb', line 190

def cast_numeric(sql_type = nil)
  cast(sql_type || Integer).sql_number
end

#cast_string(sql_type = nil) ⇒ Object

Cast the reciever to the given SQL type (or text if none given), and return the result as a StringExpression, so you can use + directly on the result for SQL string concatenation.



197
198
199
# File 'lib/sequel_core/sql.rb', line 197

def cast_string(sql_type = nil)
  cast(sql_type || String).sql_string
end