Class: PgPipeline::TypeMaps
- Inherits:
-
Object
- Object
- PgPipeline::TypeMaps
- Defined in:
- lib/pg_pipeline/type_maps.rb
Constant Summary collapse
- PENDING =
Object.new.freeze
Instance Method Summary collapse
- #apply!(request, result, _conn) ⇒ Object
- #bind(request, statement) ⇒ Object
- #cached(physical_name) ⇒ Object
- #ensure_bundle!(connection_args) ⇒ Object
-
#initialize ⇒ TypeMaps
constructor
A new instance of TypeMaps.
- #register(statement) ⇒ Object
- #typed?(physical_name) ⇒ Boolean
- #unregister(physical_name) ⇒ Object
Constructor Details
#initialize ⇒ TypeMaps
Returns a new instance of TypeMaps.
10 11 12 13 14 15 |
# File 'lib/pg_pipeline/type_maps.rb', line 10 def initialize @cache = {} @wants_typed = {} @bundle = nil @text_map_for_results = nil end |
Instance Method Details
#apply!(request, result, _conn) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pg_pipeline/type_maps.rb', line 59 def apply!(request, result, _conn) map = request.type_map return if map.nil? if map.equal?(PENDING) name = request.statement_name map = @cache[name] unless map map = build_column_map!(result) @cache[name] = map end request.type_map = map end result.type_map = map end |
#bind(request, statement) ⇒ Object
34 35 36 37 38 |
# File 'lib/pg_pipeline/type_maps.rb', line 34 def bind(request, statement) return unless statement.typed? request.type_map = @cache[statement.physical_name] || PENDING end |
#cached(physical_name) ⇒ Object
30 31 32 |
# File 'lib/pg_pipeline/type_maps.rb', line 30 def cached(physical_name) @cache[physical_name] end |
#ensure_bundle!(connection_args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pg_pipeline/type_maps.rb', line 40 def ensure_bundle!(connection_args) return if @bundle && @bundle != :failed conn = nil conn = connection_args.nil? ? PG::Connection.new : PG::Connection.new(connection_args) @bundle = PG::BasicTypeRegistry::CoderMapsBundle.new(conn) @text_map_for_results = PG::BasicTypeMapForResults.new(@bundle) rescue StandardError => e @bundle = :failed @text_map_for_results = nil raise Error, "failed to build CoderMapsBundle (#{e.class}: #{e.})" ensure begin conn&.close rescue StandardError nil end end |
#register(statement) ⇒ Object
17 18 19 |
# File 'lib/pg_pipeline/type_maps.rb', line 17 def register(statement) @wants_typed[statement.physical_name] = true if statement.typed? end |
#typed?(physical_name) ⇒ Boolean
26 27 28 |
# File 'lib/pg_pipeline/type_maps.rb', line 26 def typed?(physical_name) @wants_typed[physical_name] end |
#unregister(physical_name) ⇒ Object
21 22 23 24 |
# File 'lib/pg_pipeline/type_maps.rb', line 21 def unregister(physical_name) @cache.delete(physical_name) @wants_typed.delete(physical_name) end |