class Naginegi::MySQL::MySQLClient

Constants

COLUMN_SQL

Public Class Methods

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

Public Instance Methods

client() click to toggle source
# File lib/naginegi/mysql.rb, line 22
def client
  @client ||= Mysql2::Client.new(
    host: @database_config['host'],
    username: @database_config['username'],
    password: @database_config['password'],
    database: @database_config['database']
  )
end
columns(table_name) click to toggle source
# File lib/naginegi/mysql.rb, line 36
def columns(table_name)
  rows = client.xquery(COLUMN_SQL, @database_config['database'], table_name)
  rows.map { |row| Column.new(row['column_name'], row['data_type']) }
end
generate_bq_schema(table_name) click to toggle source
# File lib/naginegi/mysql.rb, line 31
def generate_bq_schema(table_name)
  infos = columns(table_name)
  BigQuery.generate_schema(infos)
end