Search code examples
swiftpostgresqlvaporvapor-fluent

getting multiple average columns in vapor 4 fluent


I am working on a project in vapor and I would like to calculate the average of multiple columns, but I can't figure out how to do it. I can get the average of one column like this:

let runCount = try await RunCount.query(on: req.db)
                   .filter(\.$player.$id == "Unique string")
                   .average(\.$interval1)

I have tried to parse more parameters to the average function without luck and I have also tried to call the average function multiple times.


Solution

  • Fluent can't do averages across multiple columns, primarily because the underlying syntax for each DB is so different. You could write a custom extension or drop down to raw SQL to do it instead.