mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Reduce internal coupling
This commit is contained in:
1 parent
c8023adff1
commit
dae4ae1c6b
36 files changed
+1798
-1625
No files matched your search
@@ -102,19 +102,19 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
return trivialCountQuery
|
||||
}
|
||||
|
||||
guard let source = source, case .table(name: let tableName, alias: let alias) = source else {
|
||||
guard let source = source, case .table = source else {
|
||||
// SELECT ... FROM (something which is not a table)
|
||||
return trivialCountQuery
|
||||
}
|
||||
|
||||
assert(!selection.isEmpty)
|
||||
if selection.count == 1 {
|
||||
guard let selectable = self.selection[0].countingSelectable(distinct: isDistinct, from: tableName, aliased: alias) else {
|
||||
guard let count = self.selection[0].count(distinct: isDistinct) else {
|
||||
return trivialCountQuery
|
||||
}
|
||||
var countQuery = unorderedQuery
|
||||
countQuery.isDistinct = false
|
||||
countQuery.selection = [selectable]
|
||||
countQuery.selection = [count.sqlSelectable]
|
||||
return countQuery
|
||||
} else {
|
||||
// SELECT [DISTINCT] expr1, expr2, ... FROM tableName ...
|
||||
@@ -127,7 +127,7 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
// ->
|
||||
// SELECT COUNT(*) FROM tableName ...
|
||||
var countQuery = unorderedQuery
|
||||
countQuery.selection = [SQLExpressionCount(star)]
|
||||
countQuery.selection = [SQLExpressionCount(SQLStar())]
|
||||
return countQuery
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ struct QueryInterfaceSelectQueryDefinition {
|
||||
// SELECT COUNT(*) FROM (self)
|
||||
private var trivialCountQuery: QueryInterfaceSelectQueryDefinition {
|
||||
return QueryInterfaceSelectQueryDefinition(
|
||||
select: [SQLExpressionCount(star)],
|
||||
select: [SQLExpressionCount(SQLStar())],
|
||||
from: .query(query: unorderedQuery, alias: nil))
|
||||
}
|
||||
|
||||
@@ -214,3 +214,14 @@ struct SQLLimit {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLCount {
|
||||
var sqlSelectable: SQLSelectable {
|
||||
switch self {
|
||||
case .star:
|
||||
return SQLExpressionCount(SQLStar())
|
||||
case .distinct(let expression):
|
||||
return SQLExpressionCountDistinct(expression)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user