Class: PG::BasicTypeRegistry::CoderMap
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb
Overview
An instance of this class stores the coders that should be used for a particular wire format (text or binary) and type cast direction (encoder or decoder).
Each coder object is filled with the PostgreSQL type name, OID, wire format and array coders are filled with the base elements_type.
Constant Summary collapse
- DONT_QUOTE_TYPES =
Hash of text types that don’t require quotation, when used within composite types.
type.name => true
%w[ int2 int4 int8 float4 float8 oid bool date timestamp timestamptz ].inject({}){|h,e| h[e] = true; h }
Instance Attribute Summary collapse
-
#coders ⇒ Object
readonly
Returns the value of attribute coders.
-
#coders_by_name ⇒ Object
readonly
Returns the value of attribute coders_by_name.
-
#coders_by_oid ⇒ Object
readonly
Returns the value of attribute coders_by_oid.
Instance Method Summary collapse
- #coder_by_name(name) ⇒ Object
- #coder_by_oid(oid) ⇒ Object
-
#initialize(result, coders_by_name, format, arraycoder) ⇒ CoderMap
constructor
A new instance of CoderMap.
Constructor Details
#initialize(result, coders_by_name, format, arraycoder) ⇒ CoderMap
Returns a new instance of CoderMap.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 44 def initialize(result, coders_by_name, format, arraycoder) coder_map = {} arrays, nodes = result.partition { |row| row['typinput'] == 'array_in' } # populate the base types nodes.find_all { |row| coders_by_name.key?(row['typname']) }.each do |row| coder = coders_by_name[row['typname']].dup coder.oid = row['oid'].to_i coder.name = row['typname'] coder.format = format coder_map[coder.oid] = coder end if arraycoder # populate array types arrays.each do |row| elements_coder = coder_map[row['typelem'].to_i] next unless elements_coder coder = arraycoder.new coder.oid = row['oid'].to_i coder.name = row['typname'] coder.format = format coder.elements_type = elements_coder coder.needs_quotation = !DONT_QUOTE_TYPES[elements_coder.name] coder_map[coder.oid] = coder end end @coders = coder_map.values @coders_by_name = @coders.inject({}){|h, t| h[t.name] = t; h } @coders_by_oid = @coders.inject({}){|h, t| h[t.oid] = t; h } end |
Instance Attribute Details
#coders ⇒ Object (readonly)
Returns the value of attribute coders.
79 80 81 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 79 def coders @coders end |
#coders_by_name ⇒ Object (readonly)
Returns the value of attribute coders_by_name.
81 82 83 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 81 def coders_by_name @coders_by_name end |
#coders_by_oid ⇒ Object (readonly)
Returns the value of attribute coders_by_oid.
80 81 82 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 80 def coders_by_oid @coders_by_oid end |
Instance Method Details
#coder_by_name(name) ⇒ Object
83 84 85 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 83 def coder_by_name(name) @coders_by_name[name] end |
#coder_by_oid(oid) ⇒ Object
87 88 89 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 87 def coder_by_oid(oid) @coders_by_oid[oid] end |