in Sources/XCMetricsBackendLib/Statistics/Repositories/SQLStatisticsRepository.swift [65:84]
func getCount(day: Date, using eventLoop: EventLoop) -> EventLoopFuture<DayCount> {
guard let sql = db as? SQLDatabase else {
return eventLoop.makeFailedFuture(RepositoryError.unexpected(message: "The database is not SQL"))
}
let query: SQLQueryString = """
SELECT
sum(error_count) as errors,
count(*) as builds
FROM
\(raw: Build.schema)_\(raw: day.xcm_toPartitionedTableFormat())
"""
return sql.raw(query)
.first(decoding: CountResult.self)
.flatMapAlways { result in
let count = (try? result.get()) ?? CountResult(builds: 0, errors: 0)
return eventLoop.makeSucceededFuture(DayCount(day: day, builds: count.builds, errors: count.errors))
}
}