Class: MysqlDumpToJson::MySQL::Database
- Inherits:
-
Object
- Object
- MysqlDumpToJson::MySQL::Database
- Defined in:
- lib/mysql_dump_to_json/mysql/database.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #create_table(name, fields, keys) ⇒ Object
- #describe_table(table_name) ⇒ Object
- #describe_tables ⇒ Object
-
#initialize(opts = {}) ⇒ Database
constructor
A new instance of Database.
- #table_names ⇒ Object
- #to_hash ⇒ Object
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
#opts ⇒ Object (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 |
#tables ⇒ Object (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_tables ⇒ Object
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_names ⇒ Object
26 27 28 |
# File 'lib/mysql_dump_to_json/mysql/database.rb', line 26 def table_names @tables.keys end |
#to_hash ⇒ Object
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 |