| Class | Sequel::Postgres::HStore |
| In: |
lib/sequel/extensions/pg_hstore.rb
lib/sequel/extensions/pg_hstore_ops.rb |
| Parent: | DelegateClass(Hash) |
| 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. | |
| QUOTE | = | '"'.freeze | ||
| COMMA | = | ",".freeze | ||
| KV_SEP | = | "=>".freeze | ||
| NULL | = | "NULL".freeze | ||
| ESCAPE_RE | = | /("|\\)/.freeze | ||
| ESCAPE_REPLACE | = | '\\\\\1'.freeze | ||
| HSTORE_CAST | = | '::hstore'.freeze |
| __getobj__ | -> | to_hash |
| Return the underlying hash used by this HStore instance. | ||
Use custom marshal loading, since underlying hash uses a default proc.
# File lib/sequel/extensions/pg_hstore.rb, line 205
205: def self._load(args)
206: new(Hash[Marshal.load(args)])
207: end
Use custom marshal dumping, since underlying hash uses a default proc.
# File lib/sequel/extensions/pg_hstore.rb, line 237
237: def _dump(*)
238: Marshal.dump(to_a)
239: end
Override to force the key argument to a string.
# File lib/sequel/extensions/pg_hstore.rb, line 242
242: def fetch(key, *args, &block)
243: super(key.to_s, *args, &block)
244: end
Append a literalize version of the hstore to the sql.
# File lib/sequel/extensions/pg_hstore.rb, line 256
256: def sql_literal_append(ds, sql)
257: ds.literal_append(sql, unquoted_literal)
258: sql << HSTORE_CAST
259: end
Return a string containing the unquoted, unstring-escaped literal version of the hstore. Separated out for use by the bound argument code.
# File lib/sequel/extensions/pg_hstore.rb, line 264
264: def unquoted_literal
265: str = ''
266: comma = false
267: commas = COMMA
268: quote = QUOTE
269: kv_sep = KV_SEP
270: null = NULL
271: each do |k, v|
272: str << commas if comma
273: str << quote << escape_value(k) << quote
274: str << kv_sep
275: if v.nil?
276: str << null
277: else
278: str << quote << escape_value(v) << quote
279: end
280: comma = true
281: end
282: str
283: end