-
-
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
implement jsonb_object (both variants) #4256
Conversation
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.
Thanks for opening this PR. The general definitions look fine, but I think we might need some small tweaks for correctly handling null values in all the cases.
/// # } | ||
/// ``` | ||
#[sql_name = "jsonb_object"] | ||
fn jsonb_object_with_keys_and_values<Arr: TextArrayOrNullableTextArray + MaybeNullableValue<Jsonb>>( |
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.
I think we need to use the `CombinedNullableValue trait that I've introduced in b488df4. The signature should be essentially the same as there.
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
fn jsonb_object<Arr: TextArrayOrNullableTextArray + MaybeNullableValue<Jsonb>>( |
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.
Can we add a test case for calling this function with a null value here? Something like jsonb_object::<Nullable<Array<Text>>, _>(None)
?
7ef7055
to
cdaec0c
Compare
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.
Thanks for the update. I locally checked how jsonb_object(null)
works and it seems to return a null
value. Therefore I'm not sure why the doc tests checks for an error instead, that does not seem to be correct.
/// | ||
/// let jsonb = diesel::select(jsonb_object::<Nullable<Array<Text>>, _>(None::<Vec<String>>)) | ||
/// .get_result::<Option<Value>>(connection); | ||
/// assert!(jsonb.is_err()); |
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.
That does seem to be not correct, this should return None
and no error.
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.
If I replace the current statement with this:
let jsonb = diesel::select(jsonb_object::<Nullable<Array<Text>>, _>(None::<Vec<String>>))
.get_result::<Option<Value>>(connection)?;
The test fails because of this error:
called `Result::unwrap()` on an `Err` value: DatabaseError(Unknown, "current transaction is aborted, commands ignored until end of transaction block")
I tried with different variations of the argument type, but couldn't get this error to resolve.
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.
That's likely caused by the error in the statement beforehand. Either get a new connection here or reorder the test cases to first have those without error and then these that return an error.
cdaec0c
to
ac30be5
Compare
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.
Thanks for the update, looks good now ❤️
ac30be5
to
307e9db
Compare
added support for
jsonb_object(text[])
andjsonb_object(keys[], values[])
under #4216