Vapor MySQL - not showing as an Import value

2019-07-19 17:31发布

问题:

This question is about the Swift Web Framework, Vapor.

I am trying to import VaporMySQL framework using Swift's Package Manager.

I already have the database running locally, the mySQL port is open & working, the mySQL database is working, the Vapor app is working [I have written several GET / POST requests that work].

But I can't Import VaporMySQL. This may be related to my lack of knowledge with Package.swift.

    let package = Package(
    name: "HelloWorld",        
    dependencies: [
    .Package(url: "https://github.com/qutheory/vapor.git", majorVersion: 0, minor: 10),
    .Package(url: "https://github.com/qutheory/cmysql.git", majorVersion: 0, minor: 2)

回答1:

The VaporMySQL package comes from the qutheory/vapor-mysql repository.

It looks like you've mistakenly included the libmysql wrapper into your project which just provides a module map for MySQL's C library.

let package = Package(
    name: "HelloWorld",        
    dependencies: [
        .Package(url: "https://github.com/qutheory/vapor.git", majorVersion: x, minor: x),
        .Package(url: "https://github.com/qutheory/vapor-mysql.git", majorVersion: x, minor: x)
    ]
)

Your Package.swift file should look like the above. The major and minor version numbers will need to be determined based on which version of Swift and Vapor you want to use.