class Baza::Driver::Mysql::Tables
This class handels various MySQL-table-specific behaviour.
Attributes
db[R]
list[R]
Public Class Methods
new(args)
click to toggle source
Constructor. This should not be called manually.
# 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
Public Instance Methods
[](table_name)
click to toggle source
Returns a table by the given table-name.
# 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()
click to toggle source
Cleans the wref-map.
# File lib/baza/driver/mysql/tables.rb, line 17 def clean @list.clean end
create(name, data, args = nil)
click to toggle source
# File lib/baza/driver/mysql/tables.rb, line 77 def create(name, data, args = nil) @db.current_database.create_table(name, data, args) end
Private Instance Methods
add_to_list(table)
click to toggle source
# File lib/baza/driver/mysql/tables.rb, line 83 def add_to_list(table) raise "Already exists: '#{table.name}'." if @list.key?(table.name) && @list[table.name].__id__ != table.__id__ @list[table.name] = table end
remove_from_list(table)
click to toggle source
# File lib/baza/driver/mysql/tables.rb, line 88 def remove_from_list(table) raise "Table not in list: '#{table.name}'." unless @list.key?(table.name) @list.delete(table.name) end