Swift 后端框架完善

Swift backend with perfct framwork

嗨,我正在学习 Swift 完美的后端,我不知道如何在我的项目中添加 mongodb 依赖项,如果有人知道该怎么做,请帮助我

import PackageDescription

let package = Package(
    name: "SwiftBackend",
    products: [
        .library(name: "PerfectMongoDB", targets: ["PerfectMongoDB"])
    ],

    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
        .package(url: "https://github.com/PerfectSideRepos/Perfect-CMongo.git", from: "0.0.0"),
        .package(url: "https://github.com/PerfectSideRepos/Perfect-CBSON.git", from: "0.0.0"),
        .package(url: "https://github.com/PerfectlySoft/PerfectLib.git", from: "3.0.0")
    ],
    targets: [
        .target(
            name: "SwiftBackend",
            dependencies: ["PerfectHTTPServer" , "PerfectLib" , "PerfectMongoDB"]),
        ]
)

请按照此说明将依赖项添加到您的 Swift 项目:

  1. 用您的项目名称创建一个空白文件夹。
  2. 在此文件夹内,使用swift package init --type=executable自动初始化Package.swift:

在你的情况下,它看起来像这样:

$ mkdir SwiftBackend && cd SwiftBackend && swift package init --type=executable
  1. 修改依赖项。应该是这样的:

    // swift-工具版本:4.0 导入 PackageDescription

    让包裹=包裹( 姓名:"SwiftBackend", 依赖项:[ .package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", 来自: "3.0.0"), .package(url: "https://github.com/PerfectlySoft/Perfect-MongoDB.git", 来自: "3.0.0"), ], 目标:[ 。目标( 姓名:"SwiftBackend", 依赖项:["PerfectHTTPServer", "PerfectMongoDB"]), ] )

可能会有一些警告,但应该可以正常工作。

我找到了它的 `import PackageDescription

让包裹=包裹( 姓名:"SwiftBackend",

products: [
    .library(name: "PerfectMongoDB", targets: ["SwiftBackend"])
],

dependencies: [
    // Dependencies declare other packages that this package depends on.
    .package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
    .package(url: "https://github.com/PerfectlySoft/Perfect-MongoDB.git", from: "0.0.0"),
    .package(url: "https://github.com/PerfectlySoft/PerfectLib.git", from: "3.0.0")
],
targets: [
    .target(
        name: "SwiftBackend",
      dependencies: ["PerfectHTTPServer" , "PerfectLib" , "MongoDB"]),
    ]

)`