Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
How to use a string PostgreSQL query in Vapor using Fluent?

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?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!