Class: Pgoutput::Decoder::RowBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pgoutput/decoder/row_builder.rb

Overview

Builds decoded row hashes from Relation metadata and TupleValue arrays.

Instance Method Summary collapse

Constructor Details

#initialize(type_registry: TypeRegistry.default) ⇒ void

Parameters:

  • type_registry (TypeRegistry) (defaults to: TypeRegistry.default)


11
12
13
14
# File 'lib/pgoutput/decoder/row_builder.rb', line 11

def initialize(type_registry: TypeRegistry.default)
  @value_decoder = ValueDecoder.new(type_registry: type_registry)
  freeze
end

Instance Method Details

#build(relation, tuple) ⇒ Hash<String, Object>

Build a decoded row hash.

Parameters:

  • relation (Pgoutput::Messages::Relation)
  • tuple (Array<Pgoutput::Messages::TupleValue>)

Returns:

  • (Hash<String, Object>)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pgoutput/decoder/row_builder.rb', line 21

def build(relation, tuple)
  row = {}

  tuple.each_with_index do |tuple_value, index|
    column = relation.columns[index]
    next unless column

    normalized_value = normalize_oid(tuple_value, column.oid)
    row[column.name] = @value_decoder.decode(normalized_value)
  end

  Ractor.make_shareable(row.freeze)
end