Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions Tests/StructuredQueriesTests/UpdateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ extension SnapshotTests {
as: .sql
) {
"""

"""
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ extension SnapshotTests {

@Test func complexMutation() {
let updateQuery =
Reminder
Reminder
.find(1)
.update {
$0.dueDate = Case()
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile error here

$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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using selections table name instead of root's table name

"""
}
}
Expand All @@ -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?
}