Class: Sequel::Postgres::HStore::Parser

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/sequel/extensions/pg_hstore.rb

Overview

Parser for PostgreSQL hstore output format.

Instance Method Summary collapse

Instance Method Details

#parseObject

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.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sequel/extensions/pg_hstore.rb', line 108

def parse
  return @result if @result
  hash = {}
  while !eos?
    skip(/"/)
    k = parse_quoted
    skip(/"\s*=>\s*/)
    if skip(/"/)
      v = parse_quoted
      skip(/"/)
    else
      scan(/NULL/)
      v = nil
    end
    skip(/,\s*/)
    hash[k] = v
  end
  @result = hash
end