Skip to content

Commit 190e8c8

Browse files
committed
count fixes
1 parent 2011e1b commit 190e8c8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Sources/Fluent/Query/Query.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ extension QueryRepresentable {
158158
public func count() throws -> Int {
159159
let query = try makeQuery()
160160
query.action = .count
161-
return try query.raw().int ?? 0
161+
162+
let raw = try query.raw()
163+
164+
guard let count = raw[0, "_fluent_count"]?.int else {
165+
throw QueryError.notSupported("Count not supported.")
166+
}
167+
168+
return count
162169
}
163170

164171
//MARK: Create

Sources/Fluent/SQL/GeneralSQLSerializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ open class GeneralSQLSerializer: SQLSerializer {
7373
var statement: [String] = []
7474
var values: [Node] = []
7575

76-
statement += "SELECT COUNT(*) FROM"
76+
statement += "SELECT COUNT(*) as _fluent_count FROM"
7777
statement += sql(table)
7878

7979
if !unions.isEmpty {

0 commit comments

Comments
 (0)