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

#[derive(FromRow)] should support columns which may be omitted from the result set #308

Closed
abonander opened this issue May 8, 2020 · 0 comments · Fixed by #495
Closed
Labels
E-easy good first issue Good for newcomers help wanted Extra attention is needed

Comments

@abonander
Copy link
Collaborator

abonander commented May 8, 2020

We should provide the ability to mark fields with #[sqlx(defaultl)] which allows them to be skipped if they're not in the result set:

https://discordapp.com/channels/665528275556106240/665528275556106243/708410674748981309

#[derive(sqlx::FromRow, Serialize)]
struct MyEntity {
    ID: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[sqlx(default)] // if column is not set, uses `Default::default()` instead
    age: Option<i64>, // If this column doesn't appear in the result set, I want it to be None
}

Corresponds to #[serde(default)]: https://serde.rs/field-attrs.html#default

@mehcode mehcode added E-easy good first issue Good for newcomers help wanted Extra attention is needed labels Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants