Class: PG::BasicTypeMapForQueries
- Inherits:
-
TypeMapByClass
- Object
- TypeMap
- TypeMapByClass
- PG::BasicTypeMapForQueries
- Includes:
- BasicTypeRegistry
- Defined in:
- lib/pg/basic_type_mapping.rb
Overview
Simple set of rules for type casting common Ruby types to PostgreSQL.
OIDs of supported type casts are not hard-coded in the sources, but are retrieved from the PostgreSQL's pg_type table in PG::BasicTypeMapForQueries.new .
Query params are type casted based on the class of the given value.
Higher level libraries will most likely not make use of this class, but use their own derivation of PG::TypeMapByClass or another set of rules to choose suitable encoders and decoders for the values to be sent.
Example:
conn = PG::Connection.new
# Assign a default ruleset for type casts of input and output values.
conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn)
# Execute a query. The Integer param value is typecasted internally by PG::BinaryEncoder::Int8.
# The format of the parameter is set to 0 (text) and the OID of this parameter is set to 20 (int8).
res = conn.exec_params( "SELECT $1", [5] )
Instance Attribute Summary collapse
-
#encode_array_as ⇒ Object
Returns the value of attribute encode_array_as.
Instance Method Summary collapse
-
#initialize(connection) ⇒ BasicTypeMapForQueries
constructor
A new instance of BasicTypeMapForQueries.
Methods included from BasicTypeRegistry
alias_type, register_coder, register_type
Methods inherited from TypeMapByClass
Methods included from TypeMap::DefaultTypeMappable
#default_type_map, #default_type_map=, #with_default_type_map
Constructor Details
#initialize(connection) ⇒ BasicTypeMapForQueries
Returns a new instance of BasicTypeMapForQueries.
401 402 403 404 405 406 |
# File 'lib/pg/basic_type_mapping.rb', line 401 def initialize(connection) @coder_maps = build_coder_maps(connection) @array_encoders_by_klass = array_encoders_by_klass @encode_array_as = :array init_encoders end |
Instance Attribute Details
#encode_array_as ⇒ Object
Returns the value of attribute encode_array_as
434 435 436 |
# File 'lib/pg/basic_type_mapping.rb', line 434 def encode_array_as @encode_array_as end |