Class: DBA::TableSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/dba/table_schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(database, table_name) ⇒ TableSchema

Returns a new instance of TableSchema.



2
3
4
5
6
7
8
# 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

Instance Method Details

#column_type(column_name) ⇒ Object



18
19
20
# File 'lib/dba/table_schema.rb', line 18

def column_type(column_name)
  @column_type_hash.fetch(column_name)
end

#primary_keyObject



10
11
12
13
14
15
16
# 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