Module: ConnectionManager::MysqlAdapter
- Defined in:
- lib/connection_manager/connection_adapters/mysql_adapter.rb
Instance Method Summary collapse
-
#cached_tables ⇒ Object
Force all tables to be cached for the life connection.
- #new_tables(name = nil, database = nil, like = nil) ⇒ Object (also: #tables)
-
#table_exists?(name) ⇒ Boolean
We have to clean the name of ‘`’ and fetch table name with schema.
Instance Method Details
#cached_tables ⇒ Object
Force all tables to be cached for the life connection
5 6 7 |
# File 'lib/connection_manager/connection_adapters/mysql_adapter.rb', line 5 def cached_tables @cached_tables ||= {} end |
#new_tables(name = nil, database = nil, like = nil) ⇒ Object Also known as: tables
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/connection_manager/connection_adapters/mysql_adapter.rb', line 9 def new_tables(name = nil, database = nil, like =nil) return cached_tables[database] if cached_tables[database] && like.nil? cached_tables[database] ||= [] return [like] if like && cached_tables[database].include?(like) sql = "SHOW TABLES " sql << "IN #{database} " if database sql << "LIKE #{quote(like)}" if like result = execute(sql, 'SCHEMA') cached_tables[database] = (cached_tables[database] | result.collect { |field| field[0] }).compact end |
#table_exists?(name) ⇒ Boolean
We have to clean the name of ‘`’ and fetch table name with schema
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/connection_manager/connection_adapters/mysql_adapter.rb', line 23 def table_exists?(name) return false unless name name = name.to_s schema, table = name.split('.', 2) unless table # A table was provided without a schema table = schema schema = nil end new_tables(nil, schema, table).include?(table) end |