Skip to content

Commit 9045819

Browse files
authored
Add another Select.select overload (#64)
We need to maintain overloads that overparenthesize the arguments passed to the `select` method to work around parameter pack bugs in Swift, but were missing one.
1 parent 0702428 commit 9045819

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/StructuredQueriesCore/Statements/Select.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,18 @@ extension Select {
444444
_select(selection)
445445
}
446446

447+
/// Creates a new select statement from this one by selecting the given result column.
448+
///
449+
/// - Parameter selection: A closure that selects a result column from this select's tables.
450+
/// - Returns: A new select statement that selects the given column.
451+
@_disfavoredOverload
452+
public func select<C: QueryExpression, each J: Table>(
453+
_ selection: (From.TableColumns, repeat (each J).TableColumns) -> C
454+
) -> Select<C.QueryValue, From, (repeat each J)>
455+
where Columns == (), C.QueryValue: QueryRepresentable, Joins == (repeat each J) {
456+
_select(selection)
457+
}
458+
447459
/// Creates a new select statement from this one by appending the given result column to its
448460
/// selection.
449461
///
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import StructuredQueries
2+
3+
// NB: This is a compile-time test for a 'select' overload.
4+
@Selection
5+
private struct ReminderRow {
6+
let reminder: Reminder
7+
let isPastDue: Bool
8+
@Column(as: [String].JSONRepresentation.self)
9+
let tags: [String]
10+
}
11+
private var remindersQuery: some Statement<ReminderRow> {
12+
Reminder
13+
.limit(1)
14+
.select {
15+
ReminderRow.Columns(
16+
reminder: $0,
17+
isPastDue: true,
18+
tags: #sql("[]")
19+
)
20+
}
21+
}

0 commit comments

Comments
 (0)