I'm using Vapor 4 beta to write some APIs. I have a PostgreSQL database running in the background and I want to filter a table, and check if a particular row was created in a certain interval of dates.
My query should be like:
SELECT *
FROM notes
WHERE date BETWEEN '2020-07-03' AND '2020-07-04'
The query works great with the database (I tried it with Postico client), however I want to use it with Fluent in Xcode.
I tried something like this:
func retrieveNotes(req : Request) throws -> EventLoopFuture<[Note]> {
guard let userID = req.parameters.get("userID", as: UUID.self) else {throw Abort(.notFound)}
if let postgres = req.db as? PostgresDatabase {
return postgres.query("SELECT * FROM notes WHERE date BETWEEN '2020-07-03' AND '2020-07-04")
} else {
//throw some errors
}
}
It doesn't work, and it says: "Cannot convert return expression of type 'EventLoopFuture' to return type 'EventLoopFuture<[Note]>'"
How can I cast my result, or resolve this problem in some way?