Class | Sequel::Postgres::JSONBOp |
In: |
lib/sequel/extensions/pg_json_ops.rb
|
Parent: | JSONBaseOp |
JSONBaseOp subclass for the jsonb type.
In the method documentation examples, assume that:
jsonb_op = Sequel.pg_jsonb(:jsonb)
CONCAT | = | ["(".freeze, " || ".freeze, ")".freeze].freeze |
CONTAIN_ALL | = | ["(".freeze, " ?& ".freeze, ")".freeze].freeze |
CONTAIN_ANY | = | ["(".freeze, " ?| ".freeze, ")".freeze].freeze |
CONTAINS | = | ["(".freeze, " @> ".freeze, ")".freeze].freeze |
CONTAINED_BY | = | ["(".freeze, " <@ ".freeze, ")".freeze].freeze |
DELETE_PATH | = | ["(".freeze, " #- ".freeze, ")".freeze].freeze |
HAS_KEY | = | ["(".freeze, " ? ".freeze, ")".freeze].freeze |
jsonb expression for deletion of the given argument from the current jsonb.
jsonb_op - "a" # (jsonb - 'a')
# File lib/sequel/extensions/pg_json_ops.rb, line 300 300: def -(other) 301: self.class.new(super) 302: end
jsonb expression for concatenation of the given jsonb into the current jsonb.
jsonb_op.concat(:h) # (jsonb || h)
# File lib/sequel/extensions/pg_json_ops.rb, line 308 308: def concat(other) 309: json_op(CONCAT, wrap_input_jsonb(other)) 310: end
Removes the given path from the receiver.
jsonb_op.delete_path(:h) # (jsonb #- h)
# File lib/sequel/extensions/pg_json_ops.rb, line 343 343: def delete_path(other) 344: json_op(DELETE_PATH, wrap_input_array(other)) 345: end
Inserts the given jsonb value at the given path in the receiver. The default is to insert the value before the given path, but insert_after can be set to true to insert it after the given path.
jsonb_op.insert(['a', 'b'], h) # jsonb_insert(jsonb, ARRAY['a', 'b'], h, false) jsonb_op.insert(['a', 'b'], h, true) # jsonb_insert(jsonb, ARRAY['a', 'b'], h, true)
# File lib/sequel/extensions/pg_json_ops.rb, line 361 361: def insert(path, other, insert_after=false) 362: self.class.new(function(:insert, wrap_input_array(path), wrap_input_jsonb(other), insert_after)) 363: end
Set the given jsonb value at the given path in the receiver. By default, this will create the value if it does not exist, but create_missing can be set to false to not create a new value.
jsonb_op.set(['a', 'b'], h) # jsonb_set(jsonb, ARRAY['a', 'b'], h, true) jsonb_op.set(['a', 'b'], h, false) # jsonb_set(jsonb, ARRAY['a', 'b'], h, false)
# File lib/sequel/extensions/pg_json_ops.rb, line 383 383: def set(path, other, create_missing=true) 384: self.class.new(function(:set, wrap_input_array(path), wrap_input_jsonb(other), create_missing)) 385: end