【问题标题】:Using Fluent in a Vapor Command在 Vapor 命令中使用 Fluent
【发布时间】:2021-03-24 15:27:41
【问题描述】:

我正在尝试在命令中使用 Fluent,但遇到了这个问题:

关于这个查询:

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

我得到: Type of expression is ambiguous without more context"


当我删除过滤器时,一切都很好:

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

当我将 var 设为非可选时:

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

我得到: Cannot convert value of type 'Location?' to specified type 'Location'

相同的查询正在使用 flatMap 而不是 wait()

处理 Route

所以,我有点困惑。我的错误在哪里?

【问题讨论】:

    标签: swift vapor vapor-fluent


    【解决方案1】:

    这是一个简单的... 只是错过了

    import Fluent
    

    感谢 Discord 的 @0xTim :)

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 2019-06-20
      • 2017-02-10
      • 1970-01-01
      • 2017-08-17
      • 2020-11-16
      • 1970-01-01
      • 2017-10-10
      • 2019-05-16
      相关资源
      最近更新 更多