Class: Naginegi::MySQL::Column
- Inherits:
-
Object
- Object
- Naginegi::MySQL::Column
- Defined in:
- lib/naginegi/mysql.rb
Constant Summary collapse
- TYPE_MAPPINGS =
{ 'int' => 'INT64', 'tinyint' => 'INT64', 'smallint' => 'INT64', 'mediumint' => 'INT64', 'bigint' => 'INT64', 'float' => 'FLOAT64', 'double' => 'FLOAT64', 'decimal' => 'FLOAT64', 'char' => 'STRING', 'varchar' => 'STRING', 'tinytext' => 'STRING', 'text' => 'STRING', 'date' => 'TIMESTAMP', 'datetime' => 'TIMESTAMP', 'timestamp' => 'TIMESTAMP' }.freeze
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.
63 64 65 66 |
# File 'lib/naginegi/mysql.rb', line 63 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.
43 44 45 |
# File 'lib/naginegi/mysql.rb', line 43 def column_name @column_name end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
43 44 45 |
# File 'lib/naginegi/mysql.rb', line 43 def data_type @data_type end |
Instance Method Details
#bigquery_data_type ⇒ Object
68 69 70 |
# File 'lib/naginegi/mysql.rb', line 68 def bigquery_data_type TYPE_MAPPINGS[@data_type] || 'STRING' end |
#converted_value ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/naginegi/mysql.rb', line 72 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
84 85 86 |
# File 'lib/naginegi/mysql.rb', line 84 def to_json(*a) { 'name' => @column_name, 'type' => bigquery_data_type }.to_json(*a) end |