Skip to content
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

added support for json_strip_nulls and jsonb_strip_nulls #4255

Merged
merged 4 commits into from
Sep 13, 2024

Conversation

zaira-bibi
Copy link

Added support for functions json_strip_nulls and jsonb_strip_nulls under #4216.

Copy link
Member

@weiznich weiznich left a 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.

I added a few comments about the signatures of these functions. Additionally it would be great to have a test for json_strip_null(None) to verify that the null value handling work.

/// # Ok(())
/// # }
/// ```
fn jsonb_strip_nulls<E: MaybeNullableValue<Jsonb>>(jsonb: E) -> E::Out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to restrict the generic type E here to be either Jsonb or Nullable<Jsonb>. Also as we return the same output type as input type we don't need the MaybeNullableValue<Jsonb> helper type:

Suggested change
fn jsonb_strip_nulls<E: MaybeNullableValue<Jsonb>>(jsonb: E) -> E::Out;
fn jsonb_strip_nulls<E: JsonbOrNullableJsonb>(jsonb: E) -> E;

/// # Ok(())
/// # }
/// ```
fn json_strip_nulls<E: MaybeNullableValue<Json>>(json: E) -> E::Out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to restrict the generic type E here to be either Json or Nullable<Json>. Also as we return the same output type as input type we don't need the MaybeNullableValue helper type. You likely need to define a new JsonOrNullableJson trait analog to the JsonbOrNullableJsonb trait for that.

Suggested change
fn json_strip_nulls<E: MaybeNullableValue<Json>>(json: E) -> E::Out;
fn json_strip_nulls<E: JsonOrNullableJson>(json: E) -> E;

@zaira-bibi
Copy link
Author

@weiznich Thank you sm for the review! I have pushed in a commit for the requested changes. Please let me know if it's alright or if there are any further changes.

Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the update 🙏

weiznich

This comment was marked as duplicate.

@weiznich weiznich force-pushed the implement-json-strip-nulls branch from cc0e359 to 5f5015e Compare September 13, 2024 10:33
@weiznich weiznich enabled auto-merge September 13, 2024 10:33
@weiznich weiznich added this pull request to the merge queue Sep 13, 2024
Merged via the queue into diesel-rs:master with commit ab8903e Sep 13, 2024
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants