swift - 参数标签 '(content:)' 与任何可用的重载、swift、vapor、rest invapor、使用 postgresql 都不匹配

标签 swift postgresql rest fluent vapor

错误参数标签'(content:)'与任何可用的重载不匹配。使用postgresql,而其余部分在vapor中以获得可表示的json。模型 Controller 的语法如下,意味着数据库中的内容

import Foundation
import Vapor
import FluentProvider
import PostgreSQLProvider


final class dataPointStorage: Model, JSONRepresentable, NodeRepresentable {

//  var _data: dataPointProtocol?
//    var _data:[dataPointProtocol] = []
    let storage = Storage()
    var id: Node?
    var name:String
    var displayName:String
    var content:String
//    let temp = dataPointStorage()


    init(node:Node ,content: String?, displayName:String, name:String) {
        self.id = nil
        self.displayName = displayName
        self.name = name
    }

        static let idKey = "id"
        static let contentKey = "content"



    func forDataBase() {


        let array:[berichtDataPoint] = [intDataPoint(), boolDataPoint(), doubleDataPoint()]

        let _ = array[0] as! intDataPoint
        let _ = array[1] as! doubleDataPoint


        for point in array {

            switch point {
            case is  intDataPoint:
                print("int")
            case is doubleDataPoint:
                print("double")
            case is boolDataPoint:
                print("bool")
            default:
                print("error")
            }
        }

    }

  func makeRow() throws -> Row {
        var row = Row()
        try row.set("id", id)
        try row.set("displayName", displayName)
        try row.set("name", name)
        return row
    }

    init(row: Row) throws {
        id = try row.get("id")
        displayName = try row.get("displayName")
        name = try row.get("name")
    }

    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            "displayName": displayName,
            "name": name
            ])
    }
}

extension dataPointStorage: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create(self) { dataPointStorage in
            dataPointStorage.id()
            dataPointStorage.string("displayName")
            dataPointStorage.string("name")
            dataPointStorage.string("content")

        }
    }

    static func revert(_ database: Database) throws {
        try database.delete(dataPointStorage)
    }
}

extension dataPointStorage: JSONConvertible {
    convenience init(json: JSON) throws {
        try self.init(
       error here¶¶¶ content: json.get(dataPointStorage.contentKey)¶¶¶¶ error
        )
    }

    func makeJSON() throws -> JSON {
        var json = JSON()
        try json.set("id", id)
        try json.set("name", name)
        try json.set("displaName", displayName)
        try json.set("content", Content)

        return json
    }
}

我遵循 Vapor 中其余部分的一般上下文作为 JSON 可表示的内容,但没有解决这个简单错误的原因。

最佳答案

看起来您正在尝试调用此 init?

init(node:Node ,content: String?, displayName:String, name:String)

如果是这种情况,您需要传入其余参数,因为它们没有可用的默认值:

convenience init(json: JSON) throws {
    try self.init(
        node: <VALUE>,
        content: json.get(dataPointStorage.contentKey),
        displayName: <VALUE>,
        name: <VALULE>
    )
}

这将解决您的问题。

关于swift - 参数标签 '(content:)' 与任何可用的重载、swift、vapor、rest invapor、使用 postgresql 都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46665944/

相关文章:

ios - 如何在 Swift 中声明多维 bool 数组?

objective-c - 主屏幕上缺少 WatchKit 应用程序图标

sql - 如何根据列值查询重复的行?

java - Controller有很多@Autowired服务

java - BOX API 上传文件 Java

android - 将 JSON 改造为 POJO

swift - 如何在一天中的不同时间创建通知?

mysql - 在 Postgres 的 having 子句中引用一个选择聚合列别名

php - 将 mysql 语句切换到 postgresql

swift - GPUImage 输入 movieURL 输出 filteredMovieURL