Method: Sequel::Postgres::JSONBaseOp#query
- Defined in:
- lib/sequel/extensions/pg_json_ops.rb
#query(path, opts = OPTS) ⇒ Object
Return the result of applying the JSON path expression to the receiver, by default returning results as jsonb. Options:
- :on_empty
-
How to handle case where path expression yields an empty set. Uses same values as :on_error option.
- :on_error
-
How to handle errors when evaluating the JSON path expression:
- :null
-
Return nil (default)
- :empty_array
-
Return an empty array
- :empty_object
-
Return an empty object
- :error
-
raise a DatabaseError
- any other value
-
used as default value
- :passing
-
Variables to pass to the JSON path expression. Keys are variable names, values are the values of the variable.
- :returning
-
The data type to return (jsonb by default)
- :wrapper
-
How to wrap returned values:
- true, :unconditional
-
Always wrap returning values in an array
- :conditional
-
Only wrap multiple return values in an array
- :omit_quotes
-
Do not wrap scalar strings in quotes
json_op.query("$.a") # json_query(json, '$.a')
json_op.query("$.a", passing: {a: 1}) # json_query(json, '$.a' PASSING 1 AS a)
json_op.query("$.a", on_error: :empty_array) # json_query(json, '$.a' EMPTY ARRAY ON ERROR)
json_op.query("$.a", returning: Time) # json_query(json, '$.a' RETURNING timestamp)
json_op.query("$.a", on_empty: 2) # json_query(json, '$.a' DEFAULT 2 ON EMPTY)
json_op.query("$.a", wrapper: true) # json_query(json, '$.a' WITH WRAPPER)
384 385 386 |
# File 'lib/sequel/extensions/pg_json_ops.rb', line 384 def query(path, opts=OPTS) self.class.new(JSONQueryOp.new(self, path, opts)) end |