Swift config.preparements.append(modelName.self)使用未解析标识符“modelName”时出错
我已经通过fluent provider的正确方法,使用vapor服务器端和PostgreSQL provider数据库为我的模型Swift建立了关系,我遵循了fluent的一般方法,但我不知道我在扩展模型名准备时犯了什么错误, 下面是我的modelName.swift和main.swift的代码 梅因·斯威夫特Swift config.preparements.append(modelName.self)使用未解析标识符“modelName”时出错,swift,postgresql,generics,fluent,vapor,Swift,Postgresql,Generics,Fluent,Vapor,我已经通过fluent provider的正确方法,使用vapor服务器端和PostgreSQL provider数据库为我的模型Swift建立了关系,我遵循了fluent的一般方法,但我不知道我在扩展模型名准备时犯了什么错误, 下面是我的modelName.swift和main.swift的代码 梅因·斯威夫特 我认为根本原因是模块分离。 如果将vapor项目创建为vapor new,则main.swift在运行模块中,modelName.swift在应用模块中 当访问其他模块类时,目标类的访
我认为根本原因是模块分离。 如果将vapor项目创建为vapor new,则main.swift在运行模块中,modelName.swift在应用模块中 当访问其他模块类时,目标类的访问级别为必须使用open或public 请注意,您还必须根据此更改修改其他方法声明
谢谢。将modelName.swift移动到运行文件夹中我将其更改为公共文件夹,但出现了相同的错误,目录main.swift位于运行模块中,modelName.swift位于应用模块内的模型文件夹中。因此,默认情况下,运行模块位于应用模块中。无法解决此错误,
import Foundation
import Vapor
import FluentProvider
import PostgreSQLProvider
final class modelName: Model {
let storage = Storage()
var id: Node?
var name:String
var displayName:String
public var content: String
init(content: String, displayName:String, name:String) {
self.content = content
self.displayName = displayName
self.name = name
}
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", idKey)
try row.set("displayName", displayName)
try row.set("name", name)
return row
}
init(row: Row) throws {
content = try row.get("content")
displayName = try row.get("displayName")
name = try row.get("name")
}
func makeNode(context: Context) throws -> Node {
return try Node(node: [
"id": id,
"content": content,
"displayName": displayName,
"name": name
])
}
}
extension modelName: Preparation {
static func prepare(_ database: Database) throws {
try database.create(self) { modelName in
modelName.id()
modelName.string("displayName")
modelName.string("name")
}
}
static func revert(_ database: Database) throws {
try database.delete(self)
}
}
import App
import Vapor
import FluentProvider
import PostgreSQLProvider
/// We have isolated all of our App's logic into
/// the App module because it makes our app
/// more testable.
///
/// In general, the executable portion of our App
/// shouldn't include much more code than is presented
/// here.
///
/// We simply initialize our Droplet, optionally
/// passing in values if necessary
/// Then, we pass it to our App's setup function
/// this should setup all the routes and special
/// features of our app
///
/// .run() runs the Droplet's commands,
/// if no command is given, it will default to "serve"
let config = try Config()
config.preparations.append(modelName.self) \\error is here '(Use of
unresolved identifier 'modelName')
let drop = try Droplet(config)
try drop.setup()
try drop.run()
// Package.swift
let package = Package(
name: "hello",
targets: [
Target(name: "App"),
Target(name: "Run", dependencies: ["App"]),
],
// modelName.swift
public class moduleName: Model {
...