Module: Sequel::SQL::CastMethods
- Included in:
- ComplexExpression, GenericComplexExpression, GenericExpression, String, Symbol
- Defined in:
- lib/sequel/sql.rb
Overview
Holds methods that are used to cast objects to differen SQL types.
Instance Method Summary collapse
-
#cast(sql_type) ⇒ Object
Cast the reciever to the given SQL type.
-
#cast_numeric(sql_type = nil) ⇒ Object
Cast the reciever to the given SQL type (or the database’s default integer type if none given), and return the result as a NumericExpression.
-
#cast_string(sql_type = nil) ⇒ Object
Cast the reciever to the given SQL type (or the database’s default string type if none given), and return the result as a StringExpression, so you can use + directly on the result for SQL string concatenation.
Instance Method Details
#cast(sql_type) ⇒ Object
Cast the reciever to the given SQL type. You can specify a ruby class as a type, and it is handled similarly to using a database independent type in the schema methods.
238 239 240 |
# File 'lib/sequel/sql.rb', line 238 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 the database’s default integer type if none given), and return the result as a NumericExpression.
244 245 246 |
# File 'lib/sequel/sql.rb', line 244 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 the database’s default string type if none given), and return the result as a StringExpression, so you can use + directly on the result for SQL string concatenation.
251 252 253 |
# File 'lib/sequel/sql.rb', line 251 def cast_string(sql_type = nil) cast(sql_type || String).sql_string end |