diff --git a/Tests/StructuredQueriesTests/UpdateTests.swift b/Tests/StructuredQueriesTests/UpdateTests.swift index 6608ce62..6c14148c 100644 --- a/Tests/StructuredQueriesTests/UpdateTests.swift +++ b/Tests/StructuredQueriesTests/UpdateTests.swift @@ -267,7 +267,7 @@ extension SnapshotTests { as: .sql ) { """ - + """ } } @@ -303,7 +303,7 @@ extension SnapshotTests { @Test func complexMutation() { let updateQuery = - Reminder + Reminder .find(1) .update { $0.dueDate = Case() @@ -352,7 +352,58 @@ extension SnapshotTests { Reminder.none.update { $0.isCompleted.toggle() } ) { """ + + """ + } + } + } + + @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 = honestValue + $0.fields.optionalCount = optionalValue + }, + 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" = "nestedFieldses"."optionalCount", "honestCount" = "nestedFieldses"."honestCount" """ } } @@ -363,3 +414,12 @@ extension SnapshotTests { var title = "" var quantity = 0 } + +@Table private struct Root { + @Columns var fields: NestedFields +} + +@Selection struct NestedFields { + var honestCount: Int = 0 + var optionalCount: Int? +}