Method: Sequel::Postgres::JSONBaseOp#exists

Defined in:
lib/sequel/extensions/pg_json_ops.rb

#exists(path, opts = OPTS) ⇒ Object

Return whether the given JSON path yields any items in the receiver. Options:

:on_error

How to handle errors when evaluating the JSON path expression.

true

Return true

false

Return false (default behavior)

:null

Return nil

:error

raise a DatabaseError

:passing

Variables to pass to the JSON path expression. Keys are variable names, values are the values of the variable.

json_op.exists("$.a") # json_exists(json, '$.a')
json_op.exists("$.a", passing: {a: 1}) # json_exists(json, '$.a' PASSING 1 AS a)
json_op.exists("$.a", on_error: :error) # json_exists(json, '$.a' ERROR ON ERROR)


280
281
282
# File 'lib/sequel/extensions/pg_json_ops.rb', line 280

def exists(path, opts=OPTS)
  Sequel::SQL::BooleanExpression.new(:NOOP, JSONExistsOp.new(self, path, opts))
end