-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
working on json_path_exists #4286
base: master
Are you sure you want to change the base?
working on json_path_exists #4286
Conversation
Thanks for working on this. The |
54b0440
to
ae53c5d
Compare
Hey @weiznich, I tried working on this again, and I somewhat got to implement the
Some pointers would be appreciated on how to implement the missing traits. |
/// # let connection = &mut establish_connection(); | ||
/// let jsonb:Value = serde_json::json!({"a":[1,2,3,4,5]}); | ||
/// let json_path = jsonpath_rust::path!("$.a[ ? (@ >= 2 && @ <= 4)]"); | ||
/// let exists = jsonb_path_exists::<Jsonb,Jsonpath,_,_>(jsonb,json_path).get_result::<bool>(connection)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to write something like that here:
/// let exists = jsonb_path_exists::<Jsonb,Jsonpath,_,_>(jsonb,json_path).get_result::<bool>(connection)?; | |
/// let exists = diesel::select(jsonb_path_exists::<Jsonb,Jsonpath,_,_>(jsonb,json_path)).get_result::<bool>(connection)?; |
The underlying issue is that just calling the sql function only creates a query fragment that only represents the function, not a full SELECT statement. By using diesel::select
you explicitly construct a SELECT statement without from cause, while using whatever you provided as select clause.
That should resolve the compiler error
@weiznich I was trying to implement the
jsonb_path_exists
function. One of its argument is of typeJsonpath
. Currently there is no such type in diesel, so I tried to implement it using thejsonpath_rust
crate.I implemented the
FromSql
trait for it, but I could not figure out how to implement theToSql
trait. I'd appreciate if you could take a look and help me with this or maybe i am going completely in the wrong direction with this?