Module: Sequel::SQL::CastMethods
- Included in:
- SpecificExpressionMethods, String
- Defined in:
- lib/sequel_core/sql.rb
Overview
Holds methods that are used to cast objects to differen SQL types.
Instance Method Summary collapse
-
#cast(sql_type) ⇒ Object
(also: #cast_as)
Cast the reciever to the given SQL type.
-
#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.
-
#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.
Instance Method Details
#cast(sql_type) ⇒ Object Also known as: cast_as
Cast the reciever to the given SQL type
181 182 183 |
# File 'lib/sequel_core/sql.rb', line 181 def cast(sql_type) IrregularFunction.new(:cast, self, :AS, sql_type.to_s.lit) 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.
188 189 190 |
# File 'lib/sequel_core/sql.rb', line 188 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.
195 196 197 |
# File 'lib/sequel_core/sql.rb', line 195 def cast_string(sql_type = nil) cast(sql_type || :text).sql_string end |