module PG::BasicTypeRegistry

def self.alias_type(format, new, old)

Alias the +old+ type to the +new+ type.
def self.alias_type(format, new, old)
	CODERS_BY_NAME[format][:encoder][new] = CODERS_BY_NAME[format][:encoder][old]
	CODERS_BY_NAME[format][:decoder][new] = CODERS_BY_NAME[format][:decoder][old]
end

def self.register_type(format, name, encoder_class, decoder_class)

the `pg_type` table.
+type+. +name+ should correspond to the `typname` column in
Register an OID type named +name+ with a typecasting encoder and decoder object in
def self.register_type(format, name, encoder_class, decoder_class)
	CODERS_BY_NAME[format] ||= { encoder: {}, decoder: {} }
	CODERS_BY_NAME[format][:encoder][name] = encoder_class.new(name: name, format: format) if encoder_class
	CODERS_BY_NAME[format][:decoder][name] = decoder_class.new(name: name, format: format) if decoder_class
end

def build_coder_maps(connection)

def build_coder_maps(connection)
	if supports_ranges?(connection)
		result = connection.exec <<-SQL
			SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype
			FROM pg_type as t
			LEFT JOIN pg_range as r ON oid = rngtypid
		SQL
	else
		result = connection.exec <<-SQL
			SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput
			FROM pg_type as t
		SQL
	end
	[
		[0, :encoder, PG::TextEncoder::Array],
		[0, :decoder, PG::TextDecoder::Array],
		[1, :encoder, nil],
		[1, :decoder, nil],
	].inject([]) do |h, (format, direction, arraycoder)|
		h[format] ||= {}
		h[format][direction] = CoderMap.new result, CODERS_BY_NAME[format][direction], format, arraycoder
		h
	end
end

def check_format_and_direction(format, direction)

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

def supports_ranges?(connection)

def supports_ranges?(connection)
	connection.server_version >= 90200
end