class DBA::TableSchema

Public Class Methods

new(database, table_name) click to toggle source
# File lib/dba/table_schema.rb, line 2
def initialize(database, table_name)
  @schema = database.schema(table_name)

  @column_type_hash = @schema.each_with_object({}) do |(column_name, column_info), hash|
    hash[column_name] = column_info[:type]
  end
end

Public Instance Methods

column_type(column_name) click to toggle source
# File lib/dba/table_schema.rb, line 18
def column_type(column_name)
  @column_type_hash.fetch(column_name)
end
primary_key() click to toggle source
# File lib/dba/table_schema.rb, line 10
def primary_key
  @schema.each do |column_name, column_info|
    return column_name if column_info[:primary_key]
  end

  return nil
end