Class: Baza::Driver::Mysql::Tables

Inherits:
Object
  • Object
show all
Defined in:
lib/baza/driver/mysql/tables.rb

Overview

This class handels various MySQL-table-specific behaviour.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dbObject (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

#cleanObject

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