class Naginegi::MySQL::Column

Constants

TYPE_MAPPINGS

Attributes

column_name[R]
data_type[R]

Public Class Methods

new(column_name, data_type) click to toggle source
# File lib/naginegi/mysql.rb, line 63
def initialize(column_name, data_type)
  @column_name = column_name
  @data_type = data_type
end

Public Instance Methods

bigquery_data_type() click to toggle source
# File lib/naginegi/mysql.rb, line 68
def bigquery_data_type
  TYPE_MAPPINGS[@data_type] || 'STRING'
end
converted_value() click to toggle source
# 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) click to toggle source
# File lib/naginegi/mysql.rb, line 84
def to_json(*a)
  { 'name' => @column_name, 'type' => bigquery_data_type }.to_json(*a)
end

Private Instance Methods

escaped_column_name() click to toggle source
# File lib/naginegi/mysql.rb, line 90
def escaped_column_name
  "`#{@column_name}`"
end