Class: DBA::TableSchema
- Inherits:
-
Object
- Object
- DBA::TableSchema
- Defined in:
- lib/dba/table_schema.rb
Instance Method Summary collapse
- #column_type(column_name) ⇒ Object
-
#initialize(database, table_name) ⇒ TableSchema
constructor
A new instance of TableSchema.
- #primary_key ⇒ Object
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_key ⇒ Object
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 |