Class: Samidare::MySQL::MySQLClient
- Inherits:
-
Object
- Object
- Samidare::MySQL::MySQLClient
- Defined in:
- lib/samidare/mysql.rb
Constant Summary collapse
- COLUMN_SQL =
" SELECT column_name, data_type\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE table_schema = ?\n AND table_name = ?\n ORDER BY ordinal_position\n"
Instance Method Summary collapse
- #client ⇒ Object
- #columns(table_name) ⇒ Object
- #generate_bq_schema(table_name) ⇒ Object
-
#initialize(database_config) ⇒ MySQLClient
constructor
A new instance of MySQLClient.
Constructor Details
#initialize(database_config) ⇒ MySQLClient
Returns a new instance of MySQLClient.
18 19 20 |
# File 'lib/samidare/mysql.rb', line 18 def initialize(database_config) @database_config = database_config end |
Instance Method Details
#client ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/samidare/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) ⇒ Object
35 36 37 38 |
# File 'lib/samidare/mysql.rb', line 35 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) ⇒ Object
30 31 32 33 |
# File 'lib/samidare/mysql.rb', line 30 def generate_bq_schema(table_name) infos = columns(table_name) BigQueryUtility.generate_schema(infos) end |