Module: PG::BasicTypeRegistry

Included in:
BasicTypeMapBasedOnResult, BasicTypeMapForQueries, BasicTypeMapForResults
Defined in:
lib/pg/basic_type_mapping.rb

Overview

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)

Defined Under Namespace

Classes: CoderMap