Class: RDBr::Catalog::Mysql

Inherits:
Reader
  • Object
show all
Defined in:
lib/rdbr/catalog/mysql.rb

Constant Summary collapse

RELATION_KINDS =
{ 'BASE TABLE' => :table, 'VIEW' => :view, 'SYSTEM VIEW' => :view }.freeze
FOREIGN_KEY_ACTIONS =
{
  'NO ACTION' => :no_action, 'RESTRICT' => :restrict, 'CASCADE' => :cascade,
  'SET NULL' => :set_null, 'SET DEFAULT' => :set_default
}.freeze
TYPE_MAPPINGS =
{
  /bigint/ => :int8, /tinyint|smallint|mediumint/ => :int2, /int|integer/ => :int4,
  /decimal|numeric/ => :numeric, /float/ => :float4, /double|real/ => :float8,
  /varchar|enum|set/ => :varchar, /char/ => :char, /text/ => :text,
  /datetime|timestamp/ => :timestamp, /date/ => :date, /time/ => :time, /year/ => :int2,
  /bool|boolean/ => :boolean, /json/ => :json, /binary|blob/ => :blob, /geometry/ => :geometry,
  /bit/ => :varbit
}.freeze

Instance Method Summary collapse

Methods inherited from Reader

for

Constructor Details

#initialize(connection, include_system: false) ⇒ Mysql

Returns a new instance of Mysql.



20
21
22
23
# File 'lib/rdbr/catalog/mysql.rb', line 20

def initialize(connection, include_system: false)
  super
  @queries = MysqlQueries.new(connection, include_system: include_system)
end

Instance Method Details

#readObject



25
26
27
28
29
30
31
32
33
# File 'lib/rdbr/catalog/mysql.rb', line 25

def read
  relations_by_namespace = queries.relations.group_by{|row| row.fetch('namespace_name') }
  namespaces = queries.namespaces.map do |namespace_row|
    name = namespace_row.fetch('name')
    relations = relations_by_namespace.fetch(name, []).map{|row| build_relation(name, row) }
    Metadata::Namespace.new(name: name, relations: relations)
  end
  Metadata::Database.new(name: database_name, adapter: database_adapter, namespaces: namespaces)
end