Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ extension DatabaseQueryCount {
on db: Database
) async throws -> UInt {
try await db.run { sql in
try await sql
let value =
try await sql
.select()
.from(Row.tableName)
.column(SQLFunction("COUNT", args: SQLLiteral.all), as: "count")
.column(
SQLFunction("COUNT", args: SQLLiteral.all),
as: "count"
)
.applyFilter(filter)
.first(decodingColumn: "count", as: UInt.self) ?? 0
.first(decodingColumn: "count", as: Int.self) ?? 0
return UInt(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension DatabaseQueryList {
.column(SQLFunction("COUNT", args: SQLLiteral.all), as: "count")
.applyFilter(query.filter)
.applyOrders(query.orders)
.first(decodingColumn: "count", as: UInt.self) ?? 0
.first(decodingColumn: "count", as: Int.self) ?? 0

let items =
try await sql
Expand All @@ -41,7 +41,7 @@ extension DatabaseQueryList {
.applyPage(query.page)
.all(decoding: Row.self)

return .init(items: items, total: total)
return .init(items: items, total: UInt(total))
}
}
}