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 skip_insertion attribute for Insertable derive macro #3862

Merged
merged 3 commits into from
Dec 8, 2023

Conversation

formlogic-kirk
Copy link
Contributor

@formlogic-kirk formlogic-kirk commented Nov 29, 2023

Address a subset of #860, specifically related to the Insertable derive macro. It's currently fairly painful to use Insertable for tables with generated columns, this pr allows fields to be skipped during insertion.

@formlogic-kirk formlogic-kirk marked this pull request as ready for review November 29, 2023 23:26
@weiznich weiznich requested a review from a team November 30, 2023 11:39
diesel_derives/src/insertable.rs Outdated Show resolved Hide resolved
let new_users: &[_] = &[UserWithLastName {
first_name: "Sean".to_string(),
last_name: "Black".to_string(),
..Default::default()
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a usage of this feature would always end up containing a part that's going to look like this where you have dummy values...
What happens with the ID though? It doesn't have the attribute so it looks like you are somewhat-implicitly setting it to zero?
And that looks encouraged by this feature...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't intending to show anything related to the id/primary key field here, so I'll remove that from the test as it's not useful. I really just want to be able to insert into tables with generated columns without having to convert into some intermediate type first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed now

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 think conceptually these changes look fine.

I somewhat agree with @Ten0 that it might make it easier to accidentally insert default values. We probably should not use such example in the documentation/tests.

That brings me to the point of things missing from this PR that needs to be fixed before merging:

  • The documentation needs to be updated:
    /// ## Optional field attributes
    (It needs to mention that attribute)
  • This requires an entry in the Changelog.md file

…e field attributes. Add changelog entry. Remove default intialization of struct fields in example test.
@formlogic-kirk
Copy link
Contributor Author

I somewhat agree with @Ten0 that it might make it easier to accidentally insert default values. We probably should not use such example in the documentation/tests.

I replaced it with a string indicating that the value will not be used, but I'm not sure how else to handle it. I could try making it an Option<String> if you think that would be clearer maybe?

@weiznich weiznich added this pull request to the merge queue Dec 8, 2023
Merged via the queue into diesel-rs:master with commit ce16e91 Dec 8, 2023
37 checks passed
Ten0 added a commit to Ten0/diesel that referenced this pull request Jan 12, 2024
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.

3 participants