Skip to content

Commit 3f56bc8

Browse files
authored
Merge pull request groue#1700 from groue/dev/all-columns-excluding
Select all columns from a table, but a few ones
2 parents 61c7fdf + 37ea21e commit 3f56bc8

32 files changed

+1245
-137
lines changed

Documentation/QueryInterfaceOrganization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,15 @@ protocol SQLSelectable {
497497
SQLSelectable feeds the `select()` method of the query interface:
498498

499499
```swift
500-
Player.select(AllColumns())
500+
Player.select(.allColumns)
501501
Player.select(Column("name"), Column("score"))
502502
```
503503

504504
All [SQLSpecificExpressible] values are selectable. Other selectable values are:
505505

506506
```swift
507507
// SELECT * FROM player
508-
Player.select(AllColumns())
508+
Player.select(.allColumns)
509509

510510
// SELECT MAX(score) AS maxScore FROM player
511511
Player.select(max(Column("score")).forKey("maxScore"))

GRDB/Documentation.docc/DatabaseSchemaRecommendations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extension Player: FetchableRecord, MutablePersistableRecord {
151151
// Required because the primary key
152152
// is the hidden rowid column.
153153
static var databaseSelection: [any SQLSelectable] {
154-
[AllColumns(), Column.rowID]
154+
[.allColumns, .rowID]
155155
}
156156

157157
// Update id upon successful insertion

GRDB/QueryInterface/SQL/Column.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ extension ColumnExpression {
6161

6262
extension ColumnExpression where Self == Column {
6363
/// The hidden rowID column.
64+
///
65+
/// For example:
66+
///
67+
/// ```swift
68+
/// // SELECT rowid FROM player
69+
/// let rowids = try Player.select(.rowID).fetchSet(db)
70+
/// ```
6471
public static var rowID: Self { Column.rowID }
6572
}
6673

GRDB/QueryInterface/SQL/SQLExpression.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,14 @@ public protocol SQLExpressible {
21362136
}
21372137

21382138
extension SQLExpressible where Self == Column {
2139-
/// The hidden rowID column
2139+
/// The hidden rowID column.
2140+
///
2141+
/// For example:
2142+
///
2143+
/// ```swift
2144+
/// // SELECT rowid FROM player
2145+
/// let rowids = try Player.select(.rowID).fetchSet(db)
2146+
/// ```
21402147
public static var rowID: Self { Column.rowID }
21412148
}
21422149

GRDB/QueryInterface/SQL/SQLRelation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ extension SQLRelation {
636636
}
637637

638638
// <https://github.com/groue/GRDB.swift/issues/1357>
639-
guard selection.allSatisfy(\.isTriviallyCountable) else {
639+
if selection.contains(where: \.requiresTrivialCount) {
640640
return try fetchTrivialCount(db)
641641
}
642642

0 commit comments

Comments
 (0)