Methods
- A
- C
- D
- I
- P
- S
- V
Instance Public methods
add(pool, table_name) Link
Add internal cache for table with table_name.
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 340 def add(pool, table_name) pool.with_connection do if data_source_exists?(pool, table_name) primary_keys(pool, table_name) columns(pool, table_name) columns_hash(pool, table_name) indexes(pool, table_name) end end end
as_schema_json() Link
cached?(table_name) Link
clear_data_source_cache!(_connection, name) Link
Clear out internal caches for the data source name.
columns(pool, table_name) Link
Get the columns for a table
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 352 def columns(pool, table_name) if ignored_table?(table_name) raise ActiveRecord::StatementInvalid.new("Table '#{table_name}' doesn't exist", connection_pool: pool) end @columns.fetch(table_name) do pool.with_connection do |connection| @columns[deep_deduplicate(table_name)] = deep_deduplicate(connection.columns(table_name)) end end end
columns_hash(pool, table_name) Link
Get the columns for a table as a hash, key is the column name value is the column object.
columns_hash?(_pool, table_name) Link
Checks whether the columns hash is already cached for a table.
data_source_exists?(pool, name) Link
A cached lookup for table existence.
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 323 def data_source_exists?(pool, name) return if ignored_table?(name) if @data_sources.empty? tables_to_cache(pool).each do |source| @data_sources[source] = true end end return @data_sources[name] if @data_sources.key? name @data_sources[deep_deduplicate(name)] = pool.with_connection do |connection| connection.data_source_exists?(name) end end
dump_to(filename) Link
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 437 def dump_to(filename) open(filename) { |f| if filename.include?(".dump") f.write(Marshal.dump(self)) elsif filename.include?(".json") f.write(JSONSchemaCacheSerializer.dump(self)) else f.write(YAML.dump(self)) end } end
indexes(pool, table_name) Link
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 377 def indexes(pool, table_name) @indexes.fetch(table_name) do pool.with_connection do |connection| if data_source_exists?(pool, table_name) @indexes[deep_deduplicate(table_name)] = deep_deduplicate(connection.indexes(table_name)) else [] end end end end
init_from_schema_json(coder, references) Link
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 299 def init_from_schema_json(coder, references) @columns = coder["columns"].transform_values { |columns| columns.map { |i| references[i] } } @columns_hash = @columns.transform_values { |columns| columns.index_by(&:name) } @primary_keys = coder["primary_keys"] @data_sources = coder["data_sources"].index_with { true } @indexes = (coder["indexes"] || {}).transform_values { |indexes| indexes.map { |i| references[i] } } @version = coder["version"] end
primary_keys(pool, table_name) Link
# File activerecord/lib/active_record/connection_adapters/schema_cache.rb, line 312 def primary_keys(pool, table_name) @primary_keys.fetch(table_name) do pool.with_connection do |connection| if data_source_exists?(pool, table_name) @primary_keys[deep_deduplicate(table_name)] = deep_deduplicate(connection.primary_key(table_name)) end end end end