pub trait SqliteAnyJsonExpressionMethods:
AnyJsonExpressionMethods
+ Expression
+ Sized {
// Provided method
fn retrieve_as_object_sqlite<T>(
self,
other: T,
) -> RetrieveAsObjectSqlite<Self, T>
where T: JsonIndex,
<T::Expression as Expression>::SqlType: SqlType { ... }
}Available on crate feature
sqlite only.Expand description
SQLite specific methods present on JSON and JSONB expressions.
Provided Methods§
Sourcefn retrieve_as_object_sqlite<T>(
self,
other: T,
) -> RetrieveAsObjectSqlite<Self, T>
fn retrieve_as_object_sqlite<T>( self, other: T, ) -> RetrieveAsObjectSqlite<Self, T>
Creates a SQLite -> expression.
This operator extracts the value associated with the given path or key from a JSON value. The right-hand side can be:
- A string path expression (e.g.,
"$.key","$.c", or"c"which is interpreted as"$.c") - An integer for array indexing (e.g.,
0for the first element, or-1for the last element on SQLite 3.47+)
Always returns a TEXT JSON representation (SQL type Json), even when the input is JSONB.
To get JSONB output, use jsonb_extract() function instead.
§Example
let json_value = serde_json::json!({
"street": "Article Circle Expressway 1",
"city": "North Pole",
"postcode": "99705",
"state": "Alaska"
});
let result = diesel::select(sql::<Json>(r#"json('{"a": {"b": [1, 2, 3]}}')"#)
.retrieve_as_object_sqlite("$.a.b[0]"))
.get_result::<serde_json::Value>(conn)?;
assert_eq!(serde_json::json!(1), result);
let result = diesel::select(sql::<Jsonb>(r#"json('{"a": [1, 2, 3]}')"#)
.retrieve_as_object_sqlite("$.a[1]"))
.get_result::<serde_json::Value>(conn)?;
assert_eq!(serde_json::json!(2), result);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.