Class: Sequel::Postgres::HStore
- Includes:
- SQL::AliasMethods
- Defined in:
- lib/sequel/extensions/pg_hstore.rb,
lib/sequel/extensions/pg_hstore_ops.rb
Defined Under Namespace
Modules: DatabaseMethods Classes: Parser
Constant Summary collapse
- DEFAULT_PROC =
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.
lambda{|h, k| h[k.to_s] unless k.is_a?(String)}
- QUOTE =
'"'.freeze
- COMMA =
",".freeze
- KV_SEP =
"=>".freeze
- NULL =
"NULL".freeze
- ESCAPE_RE =
/("|\\)/.freeze
- ESCAPE_REPLACE =
'\\\\\1'.freeze
- HSTORE_CAST =
'::hstore'.freeze
Class Method Summary collapse
-
._load(args) ⇒ Object
Use custom marshal loading, since underlying hash uses a default proc.
-
.parse(str) ⇒ Object
Parse the given string into an HStore, assuming the str is in PostgreSQL hstore output format.
Instance Method Summary collapse
-
#_dump ⇒ Object
Use custom marshal dumping, since underlying hash uses a default proc.
-
#fetch(key, *args, &block) ⇒ Object
Override to force the key argument to a string.
-
#merge(hash, &block) ⇒ Object
Convert the input hash to string keys and values before merging, and return a new HStore instance with the merged hash.
-
#op ⇒ Object
Wrap the receiver in an HStoreOp so you can easily use the PostgreSQL hstore functions and operators with it.
-
#sql_literal_append(ds, sql) ⇒ Object
Append a literalize version of the hstore to the sql.
-
#unquoted_literal ⇒ Object
Return a string containing the unquoted, unstring-escaped literal version of the hstore.
Methods included from SQL::AliasMethods
Methods inherited from Hash
#&, #case, #hstore, #pg_json, #sql_expr, #sql_negate, #sql_or, #|, #~
Class Method Details
Instance Method Details
#_dump ⇒ Object
Use custom marshal dumping, since underlying hash uses a default proc.
242 243 244 |
# File 'lib/sequel/extensions/pg_hstore.rb', line 242 def _dump(*) Marshal.dump(to_a) end |
#fetch(key, *args, &block) ⇒ Object
Override to force the key argument to a string.
247 248 249 |
# File 'lib/sequel/extensions/pg_hstore.rb', line 247 def fetch(key, *args, &block) super(key.to_s, *args, &block) end |
#merge(hash, &block) ⇒ Object
Convert the input hash to string keys and values before merging, and return a new HStore instance with the merged hash.
253 254 255 |
# File 'lib/sequel/extensions/pg_hstore.rb', line 253 def merge(hash, &block) self.class.new(super(convert_hash(hash), &block)) end |
#op ⇒ Object
Wrap the receiver in an HStoreOp so you can easily use the PostgreSQL hstore functions and operators with it.
299 300 301 |
# File 'lib/sequel/extensions/pg_hstore_ops.rb', line 299 def op HStoreOp.new(self) end |
#sql_literal_append(ds, sql) ⇒ Object
Append a literalize version of the hstore to the sql.
261 262 263 264 |
# File 'lib/sequel/extensions/pg_hstore.rb', line 261 def sql_literal_append(ds, sql) ds.literal_append(sql, unquoted_literal) sql << HSTORE_CAST end |
#unquoted_literal ⇒ Object
Return a string containing the unquoted, unstring-escaped literal version of the hstore. Separated out for use by the bound argument code.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/sequel/extensions/pg_hstore.rb', line 269 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 |