Skip to content

Commit 1b9c531

Browse files
committed
wip
1 parent 434bc10 commit 1b9c531

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

Sources/StructuredQueriesCore/Optional.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,9 @@ extension QueryExpression where QueryValue: _OptionalProtocol {
275275
public func map<T>(
276276
_ transform: (SQLQueryExpression<QueryValue.Wrapped>) -> some QueryExpression<T>
277277
) -> some QueryExpression<T?> {
278-
SQLQueryExpression(
279-
"""
280-
IIF(\(self), \(transform(SQLQueryExpression(queryFragment))), NULL)
281-
"""
282-
)
278+
Case(SQLQueryExpression("\(self) IS NULL"))
279+
.when(SQLQueryExpression("1"), then: SQLQueryExpression("NULL"))
280+
.else(SQLQueryExpression(transform(SQLQueryExpression(queryFragment)).queryFragment))
283281
}
284282

285283
/// Creates a new optional expression from this one by applying an unwrapped version of this

Tests/StructuredQueriesTests/MapTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension SnapshotTests {
2929
}
3030
) {
3131
"""
32-
SELECT IIF("optionalIntegers"."value", "increment"("optionalIntegers"."value"), NULL)
32+
SELECT CASE "optionalIntegers"."value" IS NULL WHEN 1 THEN NULL ELSE "increment"("optionalIntegers"."value") END
3333
FROM "optionalIntegers"
3434
"""
3535
} results: {

Tests/StructuredQueriesTests/SelectTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ extension SnapshotTests {
13691369
}
13701370
assertQuery(query) {
13711371
"""
1372-
SELECT ("reminders"."priority") < (3)
1372+
SELECT CASE "reminders"."priority" IS NULL WHEN 1 THEN NULL ELSE ("reminders"."priority") < (3) END
13731373
FROM "reminders"
13741374
"""
13751375
} results: {

0 commit comments

Comments
 (0)