-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
0821fdf
to
1128584
Compare
1128584
to
0ffbed6
Compare
diesel_tests/tests/insert.rs
Outdated
let new_users: &[_] = &[UserWithLastName { | ||
first_name: "Sean".to_string(), | ||
last_name: "Black".to_string(), | ||
..Default::default() |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed now
There was a problem hiding this 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:
diesel/diesel_derives/src/lib.rs
Line 324 in bc263af
/// ## Optional field attributes - This requires an entry in the
Changelog.md
file
…e field attributes. Add changelog entry. Remove default intialization of struct fields in example test.
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 |
Address a subset of #860, specifically related to the
Insertable
derive macro. It's currently fairly painful to useInsertable
for tables with generated columns, this pr allows fields to be skipped during insertion.