module Sequel::SQL::CastMethods

  1. lib/sequel/sql.rb

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

Methods

Public Instance

  1. cast
  2. cast_numeric
  3. cast_string

Public Instance methods

cast(sql_type)

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.

Sequel.function(:func).cast(:integer) # CAST(func() AS integer)
Sequel.function(:func).cast(String) # CAST(func() AS varchar(255))
[show source]
    # File lib/sequel/sql.rb
692 def cast(sql_type)
693   Cast.new(self, sql_type)
694 end
cast_numeric(sql_type = nil)

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)
[show source]
    # File lib/sequel/sql.rb
702 def cast_numeric(sql_type = nil)
703   Cast.new(self, sql_type || Integer).sql_number
704 end
cast_string(sql_type = nil)

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)
[show source]
    # File lib/sequel/sql.rb
712 def cast_string(sql_type = nil)
713   Cast.new(self, sql_type || String).sql_string
714 end