-
Notifications
You must be signed in to change notification settings - Fork 46
Fix issues with @Selection-based updates #233
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,9 +357,68 @@ extension SnapshotTests { | |
| } | ||
| } | ||
| } | ||
|
|
||
| @Suite struct SelectionUpdateTests { | ||
| @Dependency(\.defaultDatabase) var db | ||
|
|
||
| @Test func setSelectionFields() { | ||
| let honestValue: Int = 1 | ||
| let optionalValue: Int? = 1 | ||
| assertInlineSnapshot( | ||
| of: Root.update { | ||
| $0.fields.honestCount = honestValue | ||
| $0.fields.optionalCount = #bind(honestValue) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rcarver I'm not sure if I mentioned before, but While I think it's possible to add overloads to fix this. It's a pervasive problem and I'm not sure overloads are the solution...open to discuss, though! |
||
| }, | ||
| as: .sql | ||
| ) { | ||
| """ | ||
| UPDATE "roots" | ||
| SET "honestCount" = 1, "optionalCount" = 1 | ||
| """ | ||
| } | ||
| } | ||
|
|
||
| @Test func setSelectionValue() { | ||
| assertInlineSnapshot( | ||
| of: Root.update { | ||
| $0.fields = NestedFields(honestCount: 1, optionalCount: 1) | ||
| }, | ||
| as: .sql | ||
| ) { | ||
| """ | ||
| UPDATE "roots" | ||
| SET "honestCount" = 1, "optionalCount" = 1 | ||
| """ | ||
| } | ||
| } | ||
|
|
||
| @Test func readSelectionFields() { | ||
| assertInlineSnapshot( | ||
| of: Root.update { | ||
| $0.fields.optionalCount = $0.fields.optionalCount | ||
| $0.fields.honestCount = $0.fields.honestCount | ||
| }, | ||
| as: .sql | ||
| ) { | ||
| """ | ||
| UPDATE "roots" | ||
| SET "optionalCount" = "roots"."optionalCount", "honestCount" = "roots"."honestCount" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should now be fixed! Thanks for the test case! |
||
| """ | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Table private struct Item { | ||
| var title = "" | ||
| var quantity = 0 | ||
| } | ||
|
|
||
| @Table private struct Root { | ||
| @Columns var fields: NestedFields | ||
| } | ||
|
|
||
| @Selection struct NestedFields { | ||
| var honestCount: Int = 0 | ||
| var optionalCount: Int? | ||
| } | ||
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.
This is the simplest way I could come up with to fix the nested update issue. Underscored type for now since I'm not sure folks should be using it, especially if we come up with a better way to handle things in the future. But if we come up with more use cases for this type, we could consider making a proper public API.