pub fn jsonb_extract_integer<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue, json, text>(
json: json,
text: text,
) -> jsonb_extract_integer<J, json, text>Available on crate feature
__sqlite-shared only.Expand description
Extracts an integer value from a well-formed JSON or JSONB document at the given path.
Works identically to json_extract_integer for integer values.
Returns NULL if the path does not exist in the JSON document, or if the value at that
path is a JSON null.
To extract other types, use:
jsonb_extract_stringfor text valuesjsonb_extract_doublefor floating-point valuesjsonb_extract_jsonbfor JSON objects or arrays in JSONB format
This function requires at least SQLite 3.9 or newer.
ยงExample
let json = json!({"a": 2, "c": [4, 5, {"f": 7}]});
let result = diesel::select(jsonb_extract_integer::<Json, _, _>(json, "$.c[2].f"))
.get_result::<Option<i32>>(connection)?;
assert_eq!(Some(7), result);
let json = json!({"a": 3.7});
let result = diesel::select(jsonb_extract_integer::<Json, _, _>(json, "$.a"))
.get_result::<Option<i32>>(connection)?;
assert_eq!(Some(3), result);
let result = diesel::select(jsonb_extract_integer::<Nullable<Json>, _, _>(None::<Value>, "$.a"))
.get_result::<Option<i32>>(connection)?;
assert!(result.is_none());
let json = json!({"a": 2});
let result = diesel::select(jsonb_extract_integer::<Json, _, _>(json, "$.x"))
.get_result::<Option<i32>>(connection)?;
assert!(result.is_none());