Class: Chicago::Database::TypeConverters::DbTypeConverter Private
- Inherits:
-
Object
- Object
- Chicago::Database::TypeConverters::DbTypeConverter
- Defined in:
- lib/chicago/database/type_converters.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Generic type conversion strategy.
This supplements Sequel’s type conversion strategy rather than replaces it, so :boolean will still return :boolean rather than tinyint(1) in the case of mysql.
Direct Known Subclasses
Class Method Summary collapse
-
.for_db(db) ⇒ DbTypeConverter
private
Factory method that returns an appropriate type conversion stratgey for the given database.
Instance Method Summary collapse
-
#db_type(column) ⇒ Symbol
private
Returns a db type given a column definition.
-
#integer_type(min, max) ⇒ Symbol
private
Returns a database integer column type, big enough to fit values between min and max, or integer if a specific type cannot be found.
-
#string_type(min, max) ⇒ Symbol
private
Returns a database type for a string column.
-
#table_options ⇒ Hash
private
Returns sequel table options for a dimension or fact table.
Class Method Details
.for_db(db) ⇒ DbTypeConverter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Factory method that returns an appropriate type conversion stratgey for the given database.
If a database-specific strategy cannot be found, returns a generic strategy.
17 18 19 20 |
# File 'lib/chicago/database/type_converters.rb', line 17 def self.for_db(db) return MysqlTypeConverter.new if db.database_type == :mysql self.new end |
Instance Method Details
#db_type(column) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a db type given a column definition
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chicago/database/type_converters.rb', line 25 def db_type(column) case column.column_type when :integer then integer_type(column.min, column.max) when :string then string_type(column.min, column.max) when :money then :decimal when :percent then :decimal else column.column_type end end |
#integer_type(min, max) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a database integer column type, big enough to fit values between min and max, or integer if a specific type cannot be found.
60 61 62 63 64 65 66 67 |
# File 'lib/chicago/database/type_converters.rb', line 60 def integer_type(min, max) signed_limit = (SMALL_INT_MAX + 1) / 2 if min && max && ((min >= -signed_limit && max <= signed_limit - 1) || (min >= 0 && max <= SMALL_INT_MAX)) :smallint else :integer end end |
#string_type(min, max) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a database type for a string column.
49 50 51 |
# File 'lib/chicago/database/type_converters.rb', line 49 def string_type(min, max) min && max && min == max ? :char : :varchar end |
#table_options ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns sequel table options for a dimension or fact table.
None by default, but database-specific subclasses may override this.
42 43 44 |
# File 'lib/chicago/database/type_converters.rb', line 42 def {} end |