Class: 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(database: nil, name: nil) ⇒ 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, **opts) ⇒ Object
- #exists?(table_name) ⇒ Boolean
-
#initialize(db:, **args) ⇒ Tables
constructor
Constructor.
Constructor Details
#initialize(db:, **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(db:, **args) @args = args @db = 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(database: nil, name: nil) ⇒ Object (readonly)
Yields the tables of the current database.
49 50 51 |
# File 'lib/baza/driver/mysql/tables.rb', line 49 def list @list end |
Instance Method Details
#[](table_name) ⇒ Object
Returns a table by the given table-name.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/baza/driver/mysql/tables.rb', line 35 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, **opts) ⇒ Object
90 91 92 |
# File 'lib/baza/driver/mysql/tables.rb', line 90 def create(name, **opts) @db.current_database.create_table(name, **opts) end |
#exists?(table_name) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/baza/driver/mysql/tables.rb', line 21 def exists?(table_name) table_name = table_name.to_s table = @list[table_name] return true if table list(name: table_name) do return true end false end |