Class: Samidare::MySQL::Column
- Inherits:
-
Object
- Object
- Samidare::MySQL::Column
- Defined in:
- lib/samidare/mysql.rb
Constant Summary collapse
- TYPE_MAPPINGS =
{ 'int' => 'integer', 'tinyint' => 'integer', 'smallint' => 'integer', 'mediumint' => 'integer', 'bigint' => 'integer', 'float' => 'float', 'double' => 'float', 'decimal' => 'float', 'char' => 'string', 'varchar' => 'string', 'tinytext' => 'string', 'text' => 'string', 'date' => 'timestamp', 'datetime' => 'timestamp', 'timestamp' => 'timestamp' }
Instance Attribute Summary collapse
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
Instance Method Summary collapse
- #bigquery_data_type ⇒ Object
- #converted_value ⇒ Object
-
#initialize(column_name, data_type) ⇒ Column
constructor
A new instance of Column.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(column_name, data_type) ⇒ Column
Returns a new instance of Column.
86 87 88 89 |
# File 'lib/samidare/mysql.rb', line 86 def initialize(column_name, data_type) @column_name = column_name @data_type = data_type end |
Instance Attribute Details
#column_name ⇒ Object (readonly)
Returns the value of attribute column_name.
66 67 68 |
# File 'lib/samidare/mysql.rb', line 66 def column_name @column_name end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
66 67 68 |
# File 'lib/samidare/mysql.rb', line 66 def data_type @data_type end |
Instance Method Details
#bigquery_data_type ⇒ Object
91 92 93 |
# File 'lib/samidare/mysql.rb', line 91 def bigquery_data_type TYPE_MAPPINGS[@data_type] end |
#converted_value ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/samidare/mysql.rb', line 95 def converted_value if bigquery_data_type == 'timestamp' # time zone translate to UTC "UNIX_TIMESTAMP(#{escaped_column_name}) AS #{escaped_column_name}" elsif data_type == 'tinyint' # for MySQL tinyint(1) problem "CAST(#{escaped_column_name} AS signed) AS #{escaped_column_name}" else escaped_column_name end end |
#to_json(*a) ⇒ Object
107 108 109 |
# File 'lib/samidare/mysql.rb', line 107 def to_json(*a) { "name" => @column_name, "type" => bigquery_data_type }.to_json(*a) end |