class Naginegi::PostgreSQL::PgClient

Constants

COLUMN_SQL

Public Class Methods

new(db_config) click to toggle source
# File lib/naginegi/postgresql.rb, line 17
def initialize(db_config)
  @db_config = db_config
end

Public Instance Methods

client() click to toggle source
# File lib/naginegi/postgresql.rb, line 21
def client
  @client ||= PG::Connection.new(
    host: @db_config['host'],
    user: @db_config['username'],
    password: @db_config['password'],
    dbname: @db_config['database']
  )
end
columns(table_name) click to toggle source
# File lib/naginegi/postgresql.rb, line 35
def columns(table_name)
  rows = client.exec_params(COLUMN_SQL, [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/postgresql.rb, line 30
def generate_bq_schema(table_name)
  infos = columns(table_name)
  BigQuery.generate_schema(infos)
end