Skip to content

Commit 1fbf9c1

Browse files
authored
Merge branch 'main' into json-association
2 parents 4eddc50 + f360aea commit 1fbf9c1

File tree

15 files changed

+995
-555
lines changed

15 files changed

+995
-555
lines changed

Sources/StructuredQueriesCore/CaseExpression.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ public struct Cases<Base, QueryValue: _OptionalProtocol>: QueryExpression {
9797
return cases
9898
}
9999

100+
/// Adds a `WHEN` clause to a `CASE` expression.
101+
///
102+
/// - Parameters:
103+
/// - condition: A condition to test.
104+
/// - expression: A return value should the condition pass.
105+
/// - Returns: A `CASE` expression builder.
106+
public func when(
107+
_ condition: some QueryExpression<Base>,
108+
then expression: some QueryExpression<QueryValue.Wrapped>
109+
) -> Cases {
110+
var cases = self
111+
cases.cases.append(
112+
When(predicate: condition.queryFragment, expression: expression.queryFragment).queryFragment
113+
)
114+
return cases
115+
}
116+
100117
/// Terminates a `CASE` expression with an `ELSE` clause.
101118
///
102119
/// - Parameter expression: A return value should every `WHEN` condition fail.

Sources/StructuredQueriesCore/Documentation.docc/Articles/PrimaryKeyedTables.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ into the database by providing only a draft:
6161
@Row {
6262
@Column {
6363
```swift
64-
Reminder.insert(Reminder.Draft(title: "Get groceries"))
64+
Reminder
65+
.insert(Reminder.Draft(title: "Get groceries"))
6566
```
6667
}
6768
@Column {
@@ -122,8 +123,6 @@ Or even get back the entire newly inserted row:
122123
```
123124
}
124125
}
125-
```swift
126-
```
127126

128127
At times your application may want to provide the same business logic for creating a new record and
129128
editing an existing one. Your primary keyed table's `Draft` type can be used for these kinds of

0 commit comments

Comments
 (0)