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 #[sea_orm(skip)] for FromQueryResult macro #1954

Merged
merged 4 commits into from
Nov 8, 2023

Conversation

wyatt-herkamp
Copy link
Contributor

@wyatt-herkamp wyatt-herkamp commented Nov 2, 2023

#[derive(FromQueryResult)]
struct FromQueryAttributeTests {
    #[sea_orm(skip)]
    _foo: i32,
    _bar: String,
}

This will skip _foo then use Default to get the value.

Use Case

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, FromQueryResult)]
pub struct PublicUser {
    pub id: i64,
    pub name: String,
    pub username: String,
    pub avatar: String,
    pub group: Group,
    pub banned: bool,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[sea_orm(skip)]
    pub connections: UserConnections,
    pub created: DateTimeWithTimeZone,
}

So my UserConnections. That is a separate Vec. That I will grab later if needed.

So if you have table that has many that relates.

New Features

  • Add the ability to skip a field in FromQueryResult

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 3, 2023

Thank you for the contribution.
This is very much welcomed!
Just skimmed through the implementation it looks pretty, but I will review it again.

@wyatt-herkamp
Copy link
Contributor Author

Thank you for the contribution. This is very much welcomed! Just skimmed through the implementation it looks pretty, but I will review it again.

I don't know why the test is failing but I will be looking into it.

@wyatt-herkamp
Copy link
Contributor Author

The dependencies for the example rocket_okapi_example have not updated. So it cannot be updated.

@wyatt-herkamp
Copy link
Contributor Author

@tyt2y3 Hey I was wondering should I add #[sea_orm(skip = "path::to_default::function")] to this pr? It would be an optional value?

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 8, 2023

I think using Default::default is a good default. If user wants to customize the default function, I think it's better to have another attribute.

e.g. #[sea_orm(skip_with="path::to_default::function")]

or may be:

e.g. #[sea_orm(skip, default="path::to_default::function")]

I will merge this for now. Feel free to open another PR!

@tyt2y3 tyt2y3 merged commit b4010ec into SeaQL:master Nov 8, 2023
31 of 32 checks passed
Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

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

Thank you

@wyatt-herkamp wyatt-herkamp deleted the from-query-skip branch November 8, 2023 15:58
Copy link

🎉 Released In 0.12.5 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

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.

None yet

2 participants