mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Simplify SQLSource
SQLSource used to be more or less able to deal with subqueries, as in SELECT ... FROM (SELECT ...). But we had only one use case for it, the "trivial count query": SELECT COUNT(*) FROM (SELECT ...). And many opportunities for fatal errors, because such subqueries were not generally supported. So we simplify SQLSource, and implement the trivial count query in another way.
This commit is contained in:
1 parent
462461c1c9
commit
1e2d07a16f
6 files changed
+79
-191
No files matched your search
@@ -264,27 +264,7 @@ extension QueryInterfaceRequest: JoinableRequest where RowDecoder: TableRecord {
|
||||
extension QueryInterfaceRequest: TableRequest {
|
||||
/// :nodoc:
|
||||
public var databaseTableName: String {
|
||||
switch query.relation.source {
|
||||
case .table(tableName: let tableName, alias: _):
|
||||
// Use case:
|
||||
//
|
||||
// let request = Player.all()
|
||||
// request.filter(key: ...)
|
||||
// request.filter(keys: ...)
|
||||
// request.orderByPrimaryKey()
|
||||
return tableName
|
||||
case .subquery:
|
||||
// The only current use case for SQLSource.query is the
|
||||
// "trivial count query" (see SQLQuery.countQuery):
|
||||
//
|
||||
// // SELECT COUNT(*) FROM (SELECT * FROM player LIMIT 10)
|
||||
// let request = Player.limit(10)
|
||||
// let count = try request.fetchCount(db)
|
||||
//
|
||||
// This query is currently never wrapped in a QueryInterfaceRequest
|
||||
// So this fatal error can not currently happen.
|
||||
fatalError("Request is not based on a database table")
|
||||
}
|
||||
query.relation.source.tableName
|
||||
}
|
||||
|
||||
/// Creates a request that allows you to define expressions that target
|
||||
|
||||
Reference in new issue
Block a user