public final class JsonbDSL extends Object
Functions for jsonb
PostgreSQL operator support in jOOQ
Reference: https://www.postgresql.org/docs/11/functions-json.html
Constructor and Description |
---|
JsonbDSL() |
Modifier and Type | Method and Description |
---|---|
static org.jooq.Field<Jsonb> |
arrayElement(org.jooq.Field<Jsonb> jsonField,
int index)
Get JSON array element (indexed from zero, negative integers count from the end), using the
-> operator |
static org.jooq.Field<String> |
arrayElementText(org.jooq.Field<Jsonb> jsonField,
int index)
Get JSON array element as
text rather than json(b) (indexed from zero, negative integers
count from the end), using the ->> operator |
static org.jooq.Field<Jsonb> |
concat(org.jooq.Field<Jsonb> field1,
org.jooq.Field<Jsonb> field2)
Concatenate two
jsonb values into a new jsonb value using the || operator. |
static org.jooq.Condition |
containedIn(org.jooq.Field<Jsonb> left,
org.jooq.Field<Jsonb> right)
Are the
left JSON path/value entries contained at the top level within the right JSON value?
Uses the <@ operator. |
static org.jooq.Condition |
contains(org.jooq.Field<Jsonb> left,
org.jooq.Field<Jsonb> right)
Does the
left JSON value contain the right JSON path/value entries at the top level? Uses the
@> operator. |
static org.jooq.Field<Jsonb> |
delete(org.jooq.Field<Jsonb> f,
String... keysOrElements)
Delete multiple key/value pairs or string elements from left operand.
|
static org.jooq.Field<Jsonb> |
delete(org.jooq.Field<Jsonb> f,
String keyOrElement)
Delete key/value pair or string element from left operand.
|
static org.jooq.Field<Jsonb> |
deleteElement(org.jooq.Field<Jsonb> f,
int index)
Delete the array element with specified index (Negative integers count from the end).
|
static org.jooq.Field<Jsonb> |
deletePath(org.jooq.Field<Jsonb> f,
String... path)
Delete the field or element with specified path (for JSON arrays, negative integers count from the end).
|
static org.jooq.Field<Jsonb> |
field(Jsonb jsonb)
Create a jOOQ
Field wrapping the Jsonb object. |
static org.jooq.Field<Jsonb> |
field(String json)
|
static org.jooq.Field<Jsonb> |
fieldByKey(org.jooq.Field<Jsonb> jsonField,
String key)
Get JSON object field by key using the
-> operator |
static org.jooq.Field<String> |
fieldByKeyText(org.jooq.Field<Jsonb> jsonField,
String key)
Get JSON object field as
text rather than json(b) , using the ->>
operator |
static org.jooq.Condition |
hasAllKeys(org.jooq.Field<Jsonb> f,
Collection<String> keys)
Do all of these array strings exist as top-level keys? Uses the
?& operator. |
static org.jooq.Condition |
hasAllKeys(org.jooq.Field<Jsonb> f,
String... keys)
Do all of these array strings exist as top-level keys? Uses the
?& operator. |
static org.jooq.Condition |
hasAnyKey(org.jooq.Field<Jsonb> f,
Collection<String> keys)
Do any of these array strings exist as top-level keys? Uses the
?| operator. |
static org.jooq.Condition |
hasAnyKey(org.jooq.Field<Jsonb> f,
String... keys)
Do any of these array strings exist as top-level keys? Uses the
?| operator. |
static org.jooq.Condition |
hasKey(org.jooq.Field<Jsonb> f,
String key)
Does the string exist as a top-level key within the JSON value? Uses the
? operator. |
static org.jooq.Field<Jsonb> |
objectAtPath(org.jooq.Field<Jsonb> jsonField,
Collection<String> path)
Get JSON object at specified path using the
#> operator |
static org.jooq.Field<Jsonb> |
objectAtPath(org.jooq.Field<Jsonb> jsonField,
String... path)
Get JSON object at specified path using the
#> operator |
static org.jooq.Field<String> |
objectAtPathText(org.jooq.Field<Jsonb> jsonField,
Collection<String> path)
Get JSON object at specified path as
text rather than json(b) , using the #>>
operator |
static org.jooq.Field<String> |
objectAtPathText(org.jooq.Field<Jsonb> jsonField,
String... path)
Get JSON object at specified path as
text rather than json(b) , using the #>>
operator |
public static org.jooq.Field<Jsonb> field(String json)
Field
wrapping a Jsonb
object representing a jsonb
value for the JSON
string. Note that the JSON is not validated (any formatting errors will only occur when
interacting with the database).json
- JSON stringjsonb
Field
for the JSON stringpublic static org.jooq.Field<Jsonb> field(Jsonb jsonb)
Field
wrapping the Jsonb
object.jsonb
- Jsonb
object to wrapjsonb
Field
for the Jsonb
objectpublic static org.jooq.Field<Jsonb> arrayElement(org.jooq.Field<Jsonb> jsonField, int index)
Get JSON array element (indexed from zero, negative integers count from the end), using the
->
operator
Example: '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2
Example result: {"c":"baz"}
jsonField
- A JSON Field
containing an array to get the array element fromindex
- Array index; negative values count from the endField
representing the extracted array elementpublic static org.jooq.Field<String> arrayElementText(org.jooq.Field<Jsonb> jsonField, int index)
Get JSON array element as text
rather than json(b)
(indexed from zero, negative integers
count from the end), using the ->>
operator
Example: '[1,2,3]'::json->>2
Example result: 3
jsonField
- A JSON Field
containing an array to get the array element fromindex
- Array index; negative values count from the endField
representing the extracted array element, as textpublic static org.jooq.Field<Jsonb> fieldByKey(org.jooq.Field<Jsonb> jsonField, String key)
Get JSON object field by key using the ->
operator
Example: '{"a": {"b":"foo"}}'::json->'a'
Example result: {"b":"foo"}
jsonField
- The JSON Field
to extract the field fromkey
- JSON field key nameField
representing the extracted valuepublic static org.jooq.Field<String> fieldByKeyText(org.jooq.Field<Jsonb> jsonField, String key)
Get JSON object field as text
rather than json(b)
, using the ->>
operator
Example: '{"a":1,"b":2}'::json->>'b'
Example result: 2
jsonField
- The JSON Field
to extract the field fromkey
- JSON field key nameField
representing the extracted array element, as textpublic static org.jooq.Field<Jsonb> objectAtPath(org.jooq.Field<Jsonb> jsonField, String... path)
Get JSON object at specified path using the #>
operator
Example: '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'
Example result: {"c": "foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, Collection)
public static org.jooq.Field<Jsonb> objectAtPath(org.jooq.Field<Jsonb> jsonField, Collection<String> path)
Get JSON object at specified path using the #>
operator
Example: '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'
Example result: {"c": "foo"}
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified pathobjectAtPath(Field, String...)
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<Jsonb> jsonField, String... path)
Get JSON object at specified path as text
rather than json(b)
, using the #>>
operator
Example: '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'
Example result: 3
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPathText(Field, Collection)
public static org.jooq.Field<String> objectAtPathText(org.jooq.Field<Jsonb> jsonField, Collection<String> path)
Get JSON object at specified path as text
rather than json(b)
, using the #>>
operator
Example: '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'
Example result: 3
jsonField
- The JSON Field
to extract the path frompath
- Path to the the object to returnField
representing the object at the specified path, as textobjectAtPath(Field, String...)
public static org.jooq.Condition contains(org.jooq.Field<Jsonb> left, org.jooq.Field<Jsonb> right)
Does the left
JSON value contain the right
JSON path/value entries at the top level? Uses the
@>
operator.
Example: '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb
left
- The JSON Field
that should contain right
right
- The JSON Field
that should be contained in left
Condition
representing whether left
is contained in right
public static org.jooq.Condition containedIn(org.jooq.Field<Jsonb> left, org.jooq.Field<Jsonb> right)
Are the left
JSON path/value entries contained at the top level within the right
JSON value?
Uses the <@
operator.
Example: '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb
left
- The JSON Field
that should be contained in right
right
- The JSON Field
that should contain left
Condition
representing whether right
is contained in left
public static org.jooq.Condition hasKey(org.jooq.Field<Jsonb> f, String key)
Does the string exist as a top-level key within the JSON value? Uses the ?
operator.
Example: '{"a":1, "b":2}'::jsonb ? 'b'
f
- The JSON Field
that should contain the key
key
- The key that should exist at the top level in the JSONCondition
representing whether the key is contained in the JSON valuepublic static org.jooq.Condition hasAnyKey(org.jooq.Field<Jsonb> f, String... keys)
Do any of these array strings exist as top-level keys? Uses the ?|
operator.
Example: '{"a":1, "b":2, "c":3}'::jsonb ?| array['b', 'c']
f
- The JSON Field
that should contain any of the keys
keys
- List of keys that may exist in the JSON valueCondition
representing whether any of the keys
existhasAnyKey(Field, Collection)
public static org.jooq.Condition hasAnyKey(org.jooq.Field<Jsonb> f, Collection<String> keys)
Do any of these array strings exist as top-level keys? Uses the ?|
operator.
Example: '{"a":1, "b":2, "c":3}'::jsonb ?| array['b', 'c']
f
- The JSON Field
that should contain any of the keys
keys
- List of keys that may exist in the JSON valueCondition
representing whether any of the keys
existhasAnyKey(Field, String...)
public static org.jooq.Condition hasAllKeys(org.jooq.Field<Jsonb> f, String... keys)
Do all of these array strings exist as top-level keys? Uses the ?&
operator.
Example: '["a", "b"]'::jsonb ?& array['a', 'b']
f
- The JSON Field
that should contain all of the keys
keys
- List of keys that all should exist in the JSON valueCondition
representing whether all of the keys
existhasAllKeys(Field, Collection)
public static org.jooq.Condition hasAllKeys(org.jooq.Field<Jsonb> f, Collection<String> keys)
Do all of these array strings exist as top-level keys? Uses the ?&
operator.
Example: '["a", "b"]'::jsonb ?& array['a', 'b']
f
- The JSON Field
that should contain all of the keys
keys
- List of keys that all should exist in the JSON valueCondition
representing whether all of the keys
existhasAllKeys(Field, String...)
public static org.jooq.Field<Jsonb> concat(org.jooq.Field<Jsonb> field1, org.jooq.Field<Jsonb> field2)
Concatenate two jsonb
values into a new jsonb
value using the ||
operator.
Example: '["a", "b"]'::jsonb || '["c", "d"]'::jsonb
Example result: ["a", "b", "c", "d"]
field1
- Field to concatenate field2
tofield2
- Field to concatenate to field1
Field
representing a concatenation of the two JSON fieldspublic static org.jooq.Field<Jsonb> delete(org.jooq.Field<Jsonb> f, String keyOrElement)
Delete key/value pair or string element from left operand. Key/value pairs are matched based on their
key value. Uses the -
operator.
Example: '{"a": "b", "c": "d"}'::jsonb - 'a'
Example result: {"c": "d"}
f
- JSON Field
to delete the key or element fromkeyOrElement
- The key name or element value to delete from the JSON fieldField
representing the original field with the key or element deletedpublic static org.jooq.Field<Jsonb> delete(org.jooq.Field<Jsonb> f, String... keysOrElements)
Delete multiple key/value pairs or string elements from left operand. Key/value pairs are matched
based on their key value. Uses the -
operator.
Example: '{"a": "b", "c": "d", "e": "f"}'::jsonb - '{a,c}'::text[]
Example result: {"e", "f"}
f
- JSON Field
to delete the keys or elements fromkeysOrElements
- The key names or element values to delete from the JSON fieldField
representing the original field with the keys or elements deletedpublic static org.jooq.Field<Jsonb> deleteElement(org.jooq.Field<Jsonb> f, int index)
Delete the array element with specified index (Negative integers count from the end). Throws an error if top
level container is not an array. Uses the -
operator.
Example: '["a", "b"]'::jsonb - 1
Example result: ["a"]
f
- JSON Field
containing an array to delete the element fromindex
- Array index to delete; negative values count from the end of the arrayField
representing the field with the array element removedpublic static org.jooq.Field<Jsonb> deletePath(org.jooq.Field<Jsonb> f, String... path)
Delete the field or element with specified path (for JSON arrays, negative integers count from the end). Uses
the #-
operator.
Example: '["a", {"b":1,"c":2}]'::jsonb #- '{1,b}'
Example result: ["a", {"c": 2}]
f
- JSON Field
to delete the selected path frompath
- Path to the JSON element to removeField
representing the field with the chosen path removedCopyright © 2019. All rights reserved.