pub fn json_extract_double<J: JsonOrNullableJsonOrJsonbOrNullableJsonb + SingleValue, json, text>(
json: json,
text: text,
) -> json_extract_double<J, json, text>Available on crate feature
__sqlite-shared only.Expand description
Extracts a floating-point value from a well-formed JSON document at the given path.
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:
json_extract_stringfor text valuesjson_extract_integerfor integer valuesjson_extract_jsonfor JSON objects or arrays
This function requires at least SQLite 3.9 or newer.
ยงExample
let json = json!({"a": 3.14});
let result = diesel::select(json_extract_double::<Json, _, _>(json, "$.a"))
.get_result::<Option<f64>>(connection)?;
assert_eq!(Some(3.14), result);
let json = json!({"a": 7});
let result = diesel::select(json_extract_double::<Json, _, _>(json, "$.a"))
.get_result::<Option<f64>>(connection)?;
assert_eq!(Some(7.0), result);
let result = diesel::select(json_extract_double::<Nullable<Json>, _, _>(None::<Value>, "$.a"))
.get_result::<Option<f64>>(connection)?;
assert!(result.is_none());
let json = json!({"a": 3.14});
let result = diesel::select(json_extract_double::<Json, _, _>(json, "$.x"))
.get_result::<Option<f64>>(connection)?;
assert!(result.is_none());