class Sequel::Postgres::HStore

  1. lib/sequel/extensions/pg_hstore.rb
  2. lib/sequel/extensions/pg_hstore_ops.rb
  3. show all
Superclass: DelegateClass(Hash)

:nocov:

Included modules

  1. Sequel::SQL::AliasMethods

Constants

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.

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
203 def self._load(args)
204   new(Hash[Marshal.load(args)])
205 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
209 def self.parse(str)
210   new(Parser.new(str).parse)
211 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
235 def _dump(*)
236   Marshal.dump(to_a)
237 end
fetch(key, *args, &block)

Override to force the key argument to a string.

[show source]
    # File lib/sequel/extensions/pg_hstore.rb
240 def fetch(key, *args, &block)
241   super(key.to_s, *args, &block)
242 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
246 def merge(hash, &block)
247   self.class.new(super(convert_hash(hash), &block))
248 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
371 def op
372   HStoreOp.new(self)
373 end
sequel_auto_param_type(ds)

Allow automatic parameterization.

[show source]
    # File lib/sequel/extensions/pg_hstore.rb
284 def sequel_auto_param_type(ds)
285   "::hstore"
286 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
254 def sql_literal_append(ds, sql)
255   ds.literal_append(sql, unquoted_literal)
256   sql << '::hstore'
257 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
262 def unquoted_literal
263   str = String.new
264   comma = false
265   commas = ","
266   quote = '"'
267   kv_sep = "=>"
268   null = "NULL"
269   each do |k, v|
270     str << commas if comma
271     str << quote << escape_value(k) << quote
272     str << kv_sep
273     if v.nil?
274       str << null
275     else
276       str << quote << escape_value(v) << quote
277     end
278     comma = true
279   end
280   str
281 end