Method: Myq::Core#render_template

Defined in:
lib/myq/core.rb

#render_template(template_path = nil, output_template, format, params) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/myq/core.rb', line 190

def render_template(template_path = nil, output_template, format, params)
  system 'mkdir -p ' + File.dirname(output_template)
  database = @profile['database']
  tables = @client.xquery("SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = '#{database}'")
  tables.each do |table|
    table_name = table['TABLE_NAME']
    sql = %Q{SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = '#{database}' and TABLE_NAME = '#{table_name}'}
    columns = @client.xquery(sql)
    filepath = sprintf(output_template, parse_table(table_name, format))
    filewrite = File.open(filepath,'w')
    filewrite.puts ERB.new(File.read(template_path)).result(binding)
    filewrite.close
    puts "create #{table_name} => #{filepath}"
  end
end