Class: MysqlDumpToJson::MySQL::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_dump_to_json/mysql/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Database

Returns a new instance of Database.



10
11
12
13
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 10

def initialize(opts = {})
  @opts = opts
  @tables = {}
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 8

def opts
  @opts
end

#tablesObject (readonly)

Returns the value of attribute tables.



8
9
10
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 8

def tables
  @tables
end

Instance Method Details

#create_table(name, fields, keys) ⇒ Object



15
16
17
18
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 15

def create_table(name, fields, keys)
  @tables[name] = MysqlDumpToJson::MySQL::Table.new(name, fields, keys)
  @tables.fetch(name)
end

#describe_table(table_name) ⇒ Object



36
37
38
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 36

def describe_table(table_name)
  @tables.fetch(table_name).description
end

#describe_tablesObject



30
31
32
33
34
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 30

def describe_tables
  @tables.map do |table_name, table|
    table.description
  end
end

#table_namesObject



26
27
28
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 26

def table_names
  @tables.keys
end

#to_hashObject



20
21
22
23
24
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 20

def to_hash
  tables.map do |table_name, table|
    [table_name, { keys: table.keys, rows: table.rows }]
  end.to_h
end