-
-
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
add jsonb_set support #4357
add jsonb_set support #4357
Conversation
I am not sure if I did it right. I'd be glad if I can receive your instruction |
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.
LGTM. Types are correctly defined as well the nullability, Great Work!
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 submitting this PR.
I've found an potential issue with nullability inference that should be fixed. You can use the existing CombinedNullableValue
trait for this.
/// )).get_result::<Value>(connection)?; | ||
/// let expected = json!([]); | ||
/// assert_eq!(result, expected); | ||
/// |
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'm sorry to bring that up, but the following example won't infer nullablity correctly:
/// let result = diesel::select(jsonb_set::<Jsonb, Nullable<Array<Nullable<Text>>>, _, _, _>(
/// // cannot be json!(null)
/// json!([]),
/// None,
/// json!({"foo": 42})
/// )).get_result::<Value>(connection)?;
This is expected to only accept a Option<Value>
as return type as the return value will be NULL
in this case.
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 your kind instuction.
I fixed it by doing this:
before:
fn jsonb_set<
E: JsonbOrNullableJsonb + SingleValue,
Arr: TextArrayOrNullableTextArray + SingleValue
>(base: E, path: Arr, new_value: E) -> E;
after:
fn jsonb_set<
E: JsonbOrNullableJsonb + SingleValue,
Arr: TextArrayOrNullableTextArray + CombinedNullableValue<E,Jsonb>
>(base: E, path: Arr, new_value: E) -> Arr::Out;
Thanks for your instruction again!
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
add jsonb_set support function mentioned in issue #4216