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

Add Support For Decoding To Vec<T> For JSON Columns #1834

Closed
wants to merge 16 commits into from

Conversation

anshap1719
Copy link
Contributor

@anshap1719 anshap1719 commented Sep 1, 2023

PR Info

New Features

  • Add ability to decode to concrete Vec types for JSON[] columns.

Changes

  • Add ActiveEnumOfJson trait that is implemented by ActiveEnum and JSON types.
  • Auto implement TryGetable for any T where T implements ActiveEnumOfJson.
  • Auto implement TryGetable for any Vec<T> where T implements ActiveEnumOfJson, when array feature is enabled.
  • Add conditional clause in FromJsonQueryResult macro to implement the NotU8 trait for the target struct/enum when postgres-arrays feature is enabled.
  • Update DeriveActiveEnum macro to implement ActiveEnumOfJson for ActiveEnums.
  • Add ActiveEnumOfJson implementation for JSON type.
  • Add tests

@anshap1719 anshap1719 changed the title Add Add Support For Decoding To Vec<T> For JSON Columns Sep 1, 2023
@anshap1719 anshap1719 marked this pull request as ready for review September 17, 2023 08:46
@@ -396,14 +432,14 @@ mod tests {
}

test_num_value_uint!(U8, "u8", "TinyInteger", TinyInteger);
test_num_value_uint!(U16, "u16", "SmallInteger", SmallInteger);
// test_num_value_uint!(U16, "u16", "SmallInteger", SmallInteger);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tyt2y3 @billy1624 Can you please help me out with this one? I wrecked my brain a lot already but couldn't figure it out.

  1. I'm note sure why these use the Integer defs and not Unsigned defs (TinyInteger instead of TinyUnsigned for example.
  2. I just cannot figure out why these tests worked before, given that u16 doesn't implement sqlx's Decode trait and u64 doesn't implement sqlx's PgHasArray trait, so I cannot add a manual TryGetable implementation for either of them.

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 17, 2023

Thank you for the effort! I also need some time to wrap my head around it.

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 4, 2023

Thanks again for your effort. I am glad to see a proof of concept here. Having seen this, I got a slightly different idea, so please let me try on it.

@anshap1719
Copy link
Contributor Author

Thanks @tyt2y3, Reworked changes look so much better :D

@anshap1719
Copy link
Contributor Author

anshap1719 commented Oct 8, 2023

Closing in favour of #1898

@anshap1719 anshap1719 closed this Oct 8, 2023
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.

Add support for root arrays in JSON in SeaORM
2 participants