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.
This is a long overdue refactoring. I'm going to do a similar
refactoring for
InsertValues
as part of #1106, but this shares a lotof groundwork for that and is much smaller in scope.
Changeset
hasalways been entirely redundant with
QueryFragment
, but we had to keepit as a separate trait for two places where the implementation changed:
Eq
doesn't qualify the column nameis_noop
returned true (forChangeset
thiswas only the case for
None
or a tuple where all elements wereNone
)The first one is easy to solve, we just return a type other than
Eq
inAsChangeset
(there was very little reason to useEq
in the firstplace. We weren't able to re-use any of its code.)
The second one is a bit trickier, since we need to replicate the
is_noop
method inQueryFragment
. I'm fine with doing this, sinceInsertValues
has the same method (and tuples implementwalk_ast
identically for
InsertValues
andChangeset
), so it makes sense toshare them.
Originally I added an explicit
noop
method toAstPass
which we wouldcall. However, it felt weird that the impl for
()
which literally justdoes
Ok(())
didn't callnoop
. At that point I realized I could justgeneralize this to "did a method that generates SQL get called?" This
works fine for updates. I'm not 100% sure if it'll work for inserts, but
it's worth a shot.
I should note that the semantics of the new
is_noop
are slightlydifferent than the one on
InsertValues
, which explicitly states thatan empty array will return
false
. This will make it returntrue
whenwe switch inserts to use this. Since we already have to explicitly
handle empty arrays long before we start checking
is_noop
, I thinkthat's fine.