class Sequel::Postgres::HStore::Parser

  1. lib/sequel/extensions/pg_hstore.rb
Superclass: StringScanner

Parser for PostgreSQL hstore output format.

Methods

Public Instance

  1. parse

Public Instance methods

parse()

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.

[show source]
    # File lib/sequel/extensions/pg_hstore.rb
108 def parse
109   return @result if @result
110   hash = {}
111   while !eos?
112     skip(/"/)
113     k = parse_quoted
114     skip(/"\s*=>\s*/)
115     if skip(/"/)
116       v = parse_quoted
117       skip(/"/)
118     else
119       scan(/NULL/)
120       v = nil
121     end
122     skip(/,\s*/)
123     hash[k] = v
124   end
125   @result = hash
126 end