Module: Sequel::SQL::CastMethods
- Included in:
- Dataset, LiteralString, Postgres::JSONArrayBase, Postgres::JSONHashBase, Blob, ComplexExpression, GenericExpression, StringAgg, String, Symbol
- Defined in:
- lib/sequel/sql.rb
Overview
Holds methods that are used to cast objects to different 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
, so you can use the bitwise operators on the result. -
#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
691 692 693 |
# File 'lib/sequel/sql.rb', line 691 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
, so you can use the bitwise operators on the result.
Sequel.function(:func).cast_numeric # CAST(func() AS integer)
Sequel.function(:func).cast_numeric(Float) # CAST(func() AS double precision)
701 702 703 |
# File 'lib/sequel/sql.rb', line 701 def cast_numeric(sql_type = nil) Cast.new(self, 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.
Sequel.function(:func).cast_string # CAST(func() AS varchar(255))
Sequel.function(:func).cast_string(:text) # CAST(func() AS text)
711 712 713 |
# File 'lib/sequel/sql.rb', line 711 def cast_string(sql_type = nil) Cast.new(self, sql_type || String).sql_string end |