Simplify the structure and codegen of UpdateStatement
#367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main goal of this refactoring was to remove the implementations of
SaveChangesDsl
from codegen and provide them generically instead.Since I want the code outside of codegen to be as approachable as
possible, I made a few other changes to reduce the where clause of these
implementations. I still would like to reduce the where clause further,
but this is at a decent place. The following tree of changes were in
support of this goal:
table.find(id)
forT: Identifiable
.update
anddelete
UpdateTarget
to be a struct, andintroduce an
AsUpdateTarget
trait so that we can abstract overwhether the fields on that struct are a reference or not
All of this will drastically simplify the non-procedural-macro form of
#[derive(AsChangeset)]
, and hopefully lead to more refactoring in thefuture.
It should be noted that this changes the query on SQLite from
to
I can get the
LIMIT 1
back in there if needed, but it makes the where clause more complex, and I don't think it matters to keep that here. I couldn't simplify it in the way I wanted to by pullingfirst
into a separate trait because of rust-lang/rust#34260