| Class | Sequel::Postgres::HStore::Parser |
| In: |
lib/sequel/extensions/pg_hstore.rb
|
| Parent: | StringScanner |
| 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 |
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.
# File lib/sequel/extensions/pg_hstore.rb, line 110
110: def parse
111: return @result if @result
112: hash = {}
113: while !eos?
114: skip(QUOTE_RE)
115: k = parse_quoted
116: skip(KV_SEP_RE)
117: if skip(QUOTE_RE)
118: v = parse_quoted
119: skip(QUOTE_RE)
120: else
121: scan(NULL_RE)
122: v = nil
123: end
124: skip(SEP_RE)
125: hash[k] = v
126: end
127: @result = hash
128: end