mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
selectID
This reverts 7ffc332327
At the time, selectID was replaced with selectPrimaryKey(as:) because:
> Since Optional is a database value like others, selectID would be a request of optionals for records with an optional ID type:
>
> struct Player: Identifiable, MutablePersistableRecord {
> var id: Int64?
> }
>
> Player.selectID() // QueryInterface<Int64?>
>
> This is not good, because primary keys are not null. And those requests would fetch impractical types such as [Int64?], Set<Int64?>, Int64??.
This problem is reintroduced, but we now recommend against optional ids in https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/recordrecommendedpractices. And record with optional ids can use selectPrimaryKey(as:).
This commit is contained in:
1 parent
ea6d8e0123
commit
87b236dfe0
10 files changed
+140
-11
No files matched your search
@@ -251,6 +251,20 @@ extension TableRecord {
|
||||
all().selectPrimaryKey(as: type)
|
||||
}
|
||||
|
||||
/// Returns a request that selects the primary key.
|
||||
///
|
||||
/// For example:
|
||||
///
|
||||
/// ```swift
|
||||
/// // SELECT id FROM player
|
||||
/// let request = try Player.selectID()
|
||||
/// ```
|
||||
public static func selectID() -> QueryInterfaceRequest<Self.ID>
|
||||
where Self: Identifiable
|
||||
{
|
||||
all().selectID()
|
||||
}
|
||||
|
||||
/// Returns a request with the provided result columns appended to the
|
||||
/// record selection.
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user