Class: PG::BasicTypeRegistry::CoderMapsBundle

Inherits:
Object
  • Object
show all
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 CoderMap instances to be used for text and binary wire formats as well as encoder and decoder directions.

A PG::BasicTypeRegistry::CoderMapsBundle instance retrieves all type definitions from the PostgreSQL server and matches them with the coder definitions of the global PG::BasicTypeRegistry . It provides 4 separate CoderMap instances for the combinations of the two formats and directions.

A PG::BasicTypeRegistry::CoderMapsBundle instance can be used to initialize an instance of

  • PG::BasicTypeMapForResults

  • PG::BasicTypeMapForQueries

  • PG::BasicTypeMapBasedOnResult

by passing it instead of the connection object like so:

conn = PG::Connection.new
maps = PG::BasicTypeRegistry::CoderMapsBundle.new(conn)
conn.type_map_for_results = PG::BasicTypeMapForResults.new(maps)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, registry: nil) ⇒ CoderMapsBundle

Returns a new instance of CoderMapsBundle.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 111

def initialize(connection, registry: nil)
	registry ||= DEFAULT_TYPE_REGISTRY

	result = connection.exec(<<-SQL).to_a
		SELECT t.oid, t.typname, t.typelem, t.typdelim, ti.proname AS typinput
		FROM pg_type as t
		JOIN pg_proc as ti ON ti.oid = t.typinput
	SQL

	@maps = [
		[0, :encoder, PG::TextEncoder::Array],
		[0, :decoder, PG::TextDecoder::Array],
		[1, :encoder, nil],
		[1, :decoder, nil],
	].inject([]) do |h, (format, direction, arraycoder)|
		coders = registry.coders_for(format, direction) || {}
		h[format] ||= {}
		h[format][direction] = CoderMap.new(result, coders, format, arraycoder)
		h
	end

	@typenames_by_oid = result.inject({}){|h, t| h[t['oid'].to_i] = t['typname']; h }
end

Instance Attribute Details

#typenames_by_oidObject (readonly)

Returns the value of attribute typenames_by_oid.



109
110
111
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 109

def typenames_by_oid
  @typenames_by_oid
end

Instance Method Details

#each_format(direction) ⇒ Object



135
136
137
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 135

def each_format(direction)
	@maps.map { |f| f[direction] }
end

#map_for(format, direction) ⇒ Object



139
140
141
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/basic_type_registry.rb', line 139

def map_for(format, direction)
	@maps[format][direction]
end