module PG::BasicTypeRegistry

This module defines the mapping between OID and encoder/decoder classes for PG::BasicTypeMapForResults, PG::BasicTypeMapForQueries and PG::BasicTypeMapBasedOnResult.

Additional types can be added like so:

require 'pg'
require 'ipaddr'

class InetDecoder < PG::SimpleDecoder
  def decode(string, tuple=nil, field=nil)
    IPAddr.new(string)
  end
end
class InetEncoder < PG::SimpleEncoder
  def encode(ip_addr)
    ip_addr.to_s
  end
end

# 0 if for text format, can also be 1 for binary
PG::BasicTypeRegistry.register_type(0, 'inet', InetEncoder, InetDecoder)

Constants

CODERS_BY_NAME

The key of this hash maps to the `typname` column from the table. encoder_map is then dynamically built with oids as the key and Type objects as values.

ValidDirections
ValidFormats

Protected Instance Methods

check_format_and_direction(format, direction) click to toggle source
# File lib/pg/basic_type_mapping.rb, line 145
def check_format_and_direction(format, direction)
        raise(ArgumentError, "Invalid format value %p" % format) unless ValidFormats[format]
        raise(ArgumentError, "Invalid direction %p" % direction) unless ValidDirections[direction]
end