Class: Baza::Driver::Mysql::Tables
- Inherits:
-
Object
- Object
- Baza::Driver::Mysql::Tables
- Defined in:
- lib/baza/driver/mysql/tables.rb
Overview
This class handels various MySQL-table-specific behaviour.
Direct Known Subclasses
Baza::Driver::Mysql2::Tables, Baza::Driver::MysqlJava::Tables
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#list(args = {}) ⇒ Object
readonly
Yields the tables of the current database.
Instance Method Summary collapse
-
#[](table_name) ⇒ Object
Returns a table by the given table-name.
-
#clean ⇒ Object
Cleans the wref-map.
- #create(name, data, args = nil) ⇒ Object
-
#initialize(args) ⇒ Tables
constructor
Constructor.
Constructor Details
#initialize(args) ⇒ Tables
Constructor. This should not be called manually.
8 9 10 11 12 13 14 |
# File 'lib/baza/driver/mysql/tables.rb', line 8 def initialize(args) @args = args @db = @args.fetch(:db) @list_mutex = Monitor.new @list = Wref::Map.new @list_should_be_reloaded = true end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/baza/driver/mysql/tables.rb', line 5 def db @db end |
#list(args = {}) ⇒ Object (readonly)
Yields the tables of the current database.
36 37 38 |
# File 'lib/baza/driver/mysql/tables.rb', line 36 def list @list end |
Instance Method Details
#[](table_name) ⇒ Object
Returns a table by the given table-name.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/baza/driver/mysql/tables.rb', line 22 def [](table_name) table_name = table_name.to_s table = @list[table_name] return table if table list(name: table_name) do |table_i| return table_i if table_i.name == table_name end raise Baza::Errors::TableNotFound, "Table was not found: '#{table_name}'" end |
#clean ⇒ Object
Cleans the wref-map.
17 18 19 |
# File 'lib/baza/driver/mysql/tables.rb', line 17 def clean @list.clean end |
#create(name, data, args = nil) ⇒ Object
77 78 79 |
# File 'lib/baza/driver/mysql/tables.rb', line 77 def create(name, data, args = nil) @db.current_database.create_table(name, data, args) end |