Vapor - 如何访问 FluentValue 类型?

标签 vapor

这是一个 Swift、Vapor 相关的问题。

在尝试创建 ResponseRepresentable 类时如何访问 FluentValue 类型?

Vapor Model 协议(protocol)需要一个 ID;我想将我的 ID 变量分配为可选的 FluentValue。但是,我找不到它(即使在 Import Vapor 和 Import Fluent 之后)。

import Vapor
import VaporMySQL

let drop = Droplet()

drop.post(String.self, "boughtcoffee")     { request, buyerName in

   let coffeeledger = CoffeeLedger(name: buyerName, time: 0)

   guard let atLeastOneDrinker = request.data["drinker"].string else { 
       throw Abort.custom(status: .badRequest, message: "Please enter some drinkers")
}
     return coffeeledger
}

进口 Vapor 导入流利

final class CoffeeLedger: Model {
    var id: FluentValue?
    var name: String
    var time: Int

    init (name: String, time: Int){
        self.name = name
        self.time = time
    }
}

我正在关注 Vapor 视频,了解如何设置响应可表示的模型。 https://www.youtube.com/watch?v=E1ir7_s_VTw

最佳答案

FluentValue 在 Vapor 0.15 中变成了 Node。 (此时 Vapor 的当前版本是 0.16)。

此外,initserialize 方法变成了 init(node: ...)makeNode().

模型页面上的代码 ( https://vapor.github.io/documentation/fluent/model.html ) 应该是最新的并且可以与 Vapor 0.15 及更高版本一起使用。

如果您遇到特定错误,请在此处使用该错误消息创建另一个问题,我会尽力提供帮助!

关于Vapor - 如何访问 FluentValue 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38815353/

相关文章:

swift - SwiftNIO 和 Vapor 中的链式 throw future

swift - 为什么导入 Vapor 时会出现 Swift 编译器错误?

validation - Vapor - 验证器

swift - 如何在 Vapor 中处理 PUT HTTP 请求?

ios - Vapor 解释代码有困难,执行时出现401错误

swift - Vapor:日期对象以字符串格式解码,但解码器需要 double

arrays - Swift Vapor 对对象数组的错误解码

swift - Vapor 中的数据库列名称

swift - 使用 Vapor 创建和返回数据库记录

swift - Vapor join 和alsoDecode 产生大量嵌套元组