Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TypeMapInitializer
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TypeMapInitializer
- Defined in:
- lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb
Overview
This class uses the data from PostgreSQL pg_type table to build the OID -> Type mapping.
- OID is an integer representing the type.
- Type is an OID::Type object.
This class has side effects on the store
passed during initialization.
Instance Method Summary collapse
-
#initialize(store) ⇒ TypeMapInitializer
constructor
:nodoc:.
- #query_conditions_for_array_types ⇒ Object
- #query_conditions_for_known_type_names ⇒ Object
- #query_conditions_for_known_type_types ⇒ Object
- #run(records) ⇒ Object
Constructor Details
#initialize(store) ⇒ TypeMapInitializer
:nodoc:
15 16 17 |
# File 'lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb', line 15 def initialize(store) @store = store end |
Instance Method Details
#query_conditions_for_array_types ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb', line 52 def query_conditions_for_array_types known_type_oids = @store.keys.reject { |k| k.is_a?(String) } <<~SQL % [known_type_oids.join(", ")] WHERE t.typelem IN (%s) SQL end |
#query_conditions_for_known_type_names ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb', line 36 def query_conditions_for_known_type_names known_type_names = @store.keys.map { |n| "'#{n}'" } <<~SQL % known_type_names.join(", ") WHERE t.typname IN (%s) SQL end |
#query_conditions_for_known_type_types ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb', line 44 def query_conditions_for_known_type_types known_type_types = %w('r' 'e' 'd') <<~SQL % known_type_types.join(", ") WHERE t.typtype IN (%s) SQL end |
#run(records) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb', line 19 def run(records) nodes = records.reject { |row| @store.key? row["oid"].to_i } mapped = nodes.extract! { |row| @store.key? row["typname"] } ranges = nodes.extract! { |row| row["typtype"] == "r" } enums = nodes.extract! { |row| row["typtype"] == "e" } domains = nodes.extract! { |row| row["typtype"] == "d" } arrays = nodes.extract! { |row| row["typinput"] == "array_in" } composites = nodes.extract! { |row| row["typelem"].to_i != 0 } mapped.each { |row| register_mapped_type(row) } enums.each { |row| register_enum_type(row) } domains.each { |row| register_domain_type(row) } arrays.each { |row| register_array_type(row) } ranges.each { |row| register_range_type(row) } composites.each { |row| register_composite_type(row) } end |