PG::
BasicTypeRegistry class
Superclass | Object |
Included Modules |
This class defines the mapping between PostgreSQL types 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 conn = PG.connect regi = PG::BasicTypeRegistry.new.register_default_types regi.register_type(0, 'inet', InetEncoder, InetDecoder) conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn, registry: regi)
Public Class Methods
Public Instance Methods
Alias the old
type to the new
type.
Retrieve a Hash of all en- or decoders for a given wire format. The hash key is the name as defined in table pg_type
. The hash value is the registered coder object.
Register an encoder or decoder instance for casting a PostgreSQL type.
Coder#name must correspond to the typname
column in the pg_type
table. Coder#format can be 0 for text format and 1 for binary.
Populate the registry with all builtin types of ruby-pg
Register the given encoder_class
and/or decoder_class
for casting a PostgreSQL type.
name
must correspond to the typname
column in the pg_type
table. format
can be 0 for text format and 1 for binary.