class Sequel::Postgres::HStore

  1. lib/sequel/extensions/pg_hstore.rb
  2. lib/sequel/extensions/pg_hstore_ops.rb
  3. show all
Parent: Postgres

Methods

Public Class

  1. _load
  2. parse

Public Instance

  1. _dump
  2. fetch
  3. merge
  4. op
  5. sql_literal_append
  6. unquoted_literal

Included modules

  1. Sequel::SQL::AliasMethods

Constants

COMMA = ",".freeze  
DEFAULT_PROC = lambda{|h, k| h[k.to_s] unless k.is_a?(String)}  

Default proc used for all underlying HStore hashes, so that even if you grab the underlying hash, it will still convert non-string keys to strings during lookup.

ESCAPE_RE = /("|\\)/.freeze  
ESCAPE_REPLACE = '\\\\\1'.freeze  
HSTORE_CAST = '::hstore'.freeze  
KV_SEP = "=>".freeze  
NULL = "NULL".freeze  
QUOTE = '"'.freeze  

Public Class methods

_load (args)

Use custom marshal loading, since underlying hash uses a default proc.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 207
def self._load(args)
  new(Hash[Marshal.load(args)])
end
parse (str)

Parse the given string into an HStore, assuming the str is in PostgreSQL hstore output format.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 213
def self.parse(str)
  new(Parser.new(str).parse)
end

Public Instance methods

_dump (*)

Use custom marshal dumping, since underlying hash uses a default proc.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 239
def _dump(*)
  Marshal.dump(to_a)
end
fetch (key, *args, &block)

Override to force the key argument to a string.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 244
def fetch(key, *args, &block)
  super(key.to_s, *args, &block)
end
merge (hash, &block)

Convert the input hash to string keys and values before merging, and return a new HStore instance with the merged hash.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 250
def merge(hash, &block)
  self.class.new(super(convert_hash(hash), &block))
end
op ()

Wrap the receiver in an HStoreOp so you can easily use the PostgreSQL hstore functions and operators with it.

[show source]
# File lib/sequel/extensions/pg_hstore_ops.rb, line 299
def op
  HStoreOp.new(self)
end
sql_literal_append (ds, sql)

Append a literalize version of the hstore to the sql.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 258
def sql_literal_append(ds, sql)
  ds.literal_append(sql, unquoted_literal)
  sql << HSTORE_CAST
end
unquoted_literal ()

Return a string containing the unquoted, unstring-escaped literal version of the hstore. Separated out for use by the bound argument code.

[show source]
# File lib/sequel/extensions/pg_hstore.rb, line 266
def unquoted_literal
  str = ''
  comma = false
  commas = COMMA
  quote = QUOTE
  kv_sep = KV_SEP
  null = NULL
  each do |k, v|
    str << commas if comma
    str << quote << escape_value(k) << quote
    str << kv_sep
    if v.nil?
      str << null
    else
      str << quote << escape_value(v) << quote
    end
    comma = true
  end
  str
end