Class Sequel::Postgres::HStore::Parser
In: lib/sequel/extensions/pg_hstore.rb
Parent: StringScanner

Parser for PostgreSQL hstore output format.

Methods

parse  

Constants

QUOTE_RE = /"/.freeze
KV_SEP_RE = /"\s*=>\s*/.freeze
NULL_RE = /NULL/.freeze
SEP_RE = /,\s*/.freeze
QUOTED_RE = /(\\"|[^"])*/.freeze
REPLACE_RE = /\\(.)/.freeze
REPLACE_WITH = '\1'.freeze

Public Instance methods

Parse the output format that PostgreSQL uses for hstore columns. Note that this does not attempt to parse all input formats that PostgreSQL will accept. For instance, it expects all keys and non-NULL values to be quoted.

Return the resulting hash of objects. This can be called multiple times, it will cache the parsed hash on the first call and use it for subsequent calls.

[Source]

     # File lib/sequel/extensions/pg_hstore.rb, line 102
102:         def parse
103:           return @result if @result
104:           hash = {}
105:           while !eos?
106:             skip(QUOTE_RE)
107:             k = parse_quoted
108:             skip(KV_SEP_RE)
109:             if skip(QUOTE_RE)
110:               v = parse_quoted
111:               skip(QUOTE_RE)
112:             else
113:               scan(NULL_RE)
114:               v = nil
115:             end
116:             skip(SEP_RE)
117:             hash[k] = v
118:           end
119:           @result = hash
120:         end

[Validate]