Module: Mimi::DB::Dictate::Explorer
- Defined in:
- lib/mimi/db/dictate/explorer.rb
Class Method Summary collapse
-
.connection ⇒ Object
Returns ActiveRecord DB connection.
-
.discover_primary_key(table_name) ⇒ Array<Symbol>
Discovers primary key of an existing DB table.
-
.discover_schema(table_name) ⇒ Mimi::DB::Dictate::SchemaDefinition?
Discovers a schema of an existing DB table.
Class Method Details
.connection ⇒ Object
Returns ActiveRecord DB connection
82 83 84 |
# File 'lib/mimi/db/dictate/explorer.rb', line 82 def self.connection Mimi::DB.connection end |
.discover_primary_key(table_name) ⇒ Array<Symbol>
Discovers primary key of an existing DB table
75 76 77 78 |
# File 'lib/mimi/db/dictate/explorer.rb', line 75 def self.discover_primary_key(table_name) s = connection.schema(table_name).to_h s.keys.select { |name| s[name][:primary_key] } end |
.discover_schema(table_name) ⇒ Mimi::DB::Dictate::SchemaDefinition?
Discovers a schema of an existing DB table.
Returns nil if the DB table does not exist.
15 16 17 18 19 20 21 22 |
# File 'lib/mimi/db/dictate/explorer.rb', line 15 def self.discover_schema(table_name) table_name = table_name.to_sym return nil unless connection.tables.include?(table_name) sd = Mimi::DB::Dictate::SchemaDefinition.new(table_name) discover_schema_columns(sd) discover_schema_indexes(sd) sd end |