From 1fc98426a07252f8f1806465c3672a82782db32f Mon Sep 17 00:00:00 2001 From: Ferenc Viasz-Kadi Date: Thu, 18 Apr 2024 17:01:26 +0200 Subject: [PATCH 1/2] fixed uint count --- .../Database/Query/DatabaseQueryCount.swift | 14 +++++++++----- .../Database/Query/DatabaseQueryList.swift | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift b/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift index fe53ef9..46297b5 100644 --- a/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift +++ b/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift @@ -8,7 +8,7 @@ import SQLKit public protocol DatabaseQueryCount: DatabaseQueryInterface { - + static func count( filter: DatabaseFilter?, on db: Database @@ -16,18 +16,22 @@ public protocol DatabaseQueryCount: DatabaseQueryInterface { } extension DatabaseQueryCount { - + public static func count( filter: DatabaseFilter? = nil, 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) } } } diff --git a/Sources/FeatherDatabase/Database/Query/DatabaseQueryList.swift b/Sources/FeatherDatabase/Database/Query/DatabaseQueryList.swift index ea5856c..bd2dec4 100644 --- a/Sources/FeatherDatabase/Database/Query/DatabaseQueryList.swift +++ b/Sources/FeatherDatabase/Database/Query/DatabaseQueryList.swift @@ -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 @@ -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)) } } } From 1368a2ba8689d92e8f3b481e6387daf5b255d8e4 Mon Sep 17 00:00:00 2001 From: Ferenc Viasz-Kadi Date: Thu, 18 Apr 2024 17:02:33 +0200 Subject: [PATCH 2/2] formatted --- .../Database/Query/DatabaseQueryCount.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift b/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift index 46297b5..f0f0d6a 100644 --- a/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift +++ b/Sources/FeatherDatabase/Database/Query/DatabaseQueryCount.swift @@ -8,7 +8,7 @@ import SQLKit public protocol DatabaseQueryCount: DatabaseQueryInterface { - + static func count( filter: DatabaseFilter?, on db: Database @@ -16,13 +16,14 @@ public protocol DatabaseQueryCount: DatabaseQueryInterface { } extension DatabaseQueryCount { - + public static func count( filter: DatabaseFilter? = nil, on db: Database ) async throws -> UInt { try await db.run { sql in - let value = try await sql + let value = + try await sql .select() .from(Row.tableName) .column(