-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a long overdue refactoring. I'm going to do a similar refactoring for `InsertValues` as part of #1106, but this shares a lot of groundwork for that and is much smaller in scope. `Changeset` has always been entirely redundant with `QueryFragment`, but we had to keep it as a separate trait for two places where the implementation changed: - `Eq` doesn't qualify the column name - tuples skip commas when `is_noop` returned true (for `Changeset` this was only the case for `None` or a tuple where all elements were `None`) The first one is easy to solve, we just return a type other than `Eq` in `AsChangeset` (there was very little reason to use `Eq` in the first place. 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 in `QueryFragment`. I'm fine with doing this, since `InsertValues` has the same method (and tuples implement `walk_ast` identically for `InsertValues` and `Changeset`), so it makes sense to share them. Originally I added an explicit `noop` method to `AstPass` which we would call. However, it felt weird that the impl for `()` which literally just does `Ok(())` didn't call `noop`. At that point I realized I could just generalize 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 slightly different than the one on `InsertValues`, which explicitly states that an empty array will return `false`. This will make it return `true` when we switch inserts to use this. Since we already have to explicitly handle empty arrays long before we start checking `is_noop`, I think that's fine.
- Loading branch information
Showing
7 changed files
with
93 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters