Search code examples
swiftvaporvapor-fluent

Using Fluent in a Vapor Command


I'm trying to use Fluent in a Command and I have this problem:

On this query:

let location: Location? = try? Location.query(on: context.application.db).filter(\.geId == 123).first().wait()

I get: Type of expression is ambiguous without more context"


When I remove the filter, everything is fine:

let location: Location? = try? Location.query(on: context.application.db).first().wait()

When I make the var non optional:

let location: Location = try? Location.query(on: context.application.db).filter(\.geId == 123).first().wait()

I get: Cannot convert value of type 'Location?' to specified type 'Location'

The same query is working on a Route with flatMap instead of the wait()

So, I'm a bit confused. Where ist my error?


Solution

  • This was a simple one... Just missing the

    import Fluent
    

    Thanks to @0xTim at Discord :)