class PG::BasicTypeRegistry::CoderMapsBundle
conn.type_map_for_results = PG::BasicTypeMapForResults.new(maps)
maps = PG::BasicTypeRegistry::CoderMapsBundle.new(conn)
conn = PG::Connection.new
by passing it instead of the connection object like so:
* PG::BasicTypeMapBasedOnResult
* PG::BasicTypeMapForQueries
* PG::BasicTypeMapForResults
A PG::BasicTypeRegistry::CoderMapsBundle instance can be used to initialize an instance of
It provides 4 separate CoderMap instances for the combinations of the two formats and 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 .
as well as encoder and decoder directions.
An instance of this class stores CoderMap instances to be used for text and binary wire formats
def each_format(direction)
def each_format(direction) @maps.map { |f| f[direction] } end
def init_maps(registry, result)
def init_maps(registry, result) [ ncoder, PG::TextEncoder::Array], ecoder, PG::TextDecoder::Array], ncoder, nil], ecoder, nil], t([]) do |h, (format, direction, arraycoder)| = registry.coders_for(format, direction) || {} at] ||= {} at][direction] = CoderMap.new(result, coders, format, arraycoder) h{|h| h.freeze }.freeze mes_by_oid = result.inject({}){|h, t| h[t['oid'].to_i] = t['typname']; h }.freeze
def initialize(connection, registry: nil)
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 init_maps(registry, result.freeze) freeze end
def map_for(format, direction)
def map_for(format, direction) @maps[format][direction] end