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)

Methods

-   concat   contain_all   contain_any   contained_by   contains   delete_path   has_key?   include?   insert   pg_jsonb   pretty   set  

Constants

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

Public Instance methods

jsonb expression for deletion of the given argument from the current jsonb.

  jsonb_op - "a" # (jsonb - 'a')

[Source]

     # 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)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 308
308:       def concat(other)
309:         json_op(CONCAT, wrap_input_jsonb(other))
310:       end

Check if the receiver contains all of the keys in the given array:

  jsonb_op.contain_all(:a) # (jsonb ?& a)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 315
315:       def contain_all(other)
316:         bool_op(CONTAIN_ALL, wrap_input_array(other))
317:       end

Check if the receiver contains any of the keys in the given array:

  jsonb_op.contain_any(:a) # (jsonb ?| a)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 322
322:       def contain_any(other)
323:         bool_op(CONTAIN_ANY, wrap_input_array(other))
324:       end

Check if the other jsonb contains all entries in the receiver:

  jsonb_op.contained_by(:h) # (jsonb <@ h)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 336
336:       def contained_by(other)
337:         bool_op(CONTAINED_BY, wrap_input_jsonb(other))
338:       end

Check if the receiver contains all entries in the other jsonb:

  jsonb_op.contains(:h) # (jsonb @> h)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 329
329:       def contains(other)
330:         bool_op(CONTAINS, wrap_input_jsonb(other))
331:       end

Removes the given path from the receiver.

  jsonb_op.delete_path(:h) # (jsonb #- h)

[Source]

     # 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

Check if the receiver contains the given key:

  jsonb_op.has_key?('a') # (jsonb ? 'a')

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 350
350:       def has_key?(key)
351:         bool_op(HAS_KEY, key)
352:       end
include?(key)

Alias for has_key?

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)

[Source]

     # 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

Return the receiver, since it is already a JSONBOp.

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 366
366:       def pg_jsonb
367:         self
368:       end

Return a pretty printed version of the receiver as a string expression.

  jsonb_op.pretty # jsonb_pretty(jsonb)

[Source]

     # File lib/sequel/extensions/pg_json_ops.rb, line 373
373:       def pretty
374:         Sequel::SQL::StringExpression.new(:NOOP, function(:pretty))
375:       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)

[Source]

     # 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

[Validate]