Q:

Setting up database connection using Vapor framework

I'm trying to build APIs using Swift and I've chosen to use Vapor. 
I've created a SQLite database and am able to connect to it using a DB client. 
Now I want my Swift Vapor project to connect to it as well using the FluentSQLite package. 
I've created my database in the root folder of my project: 
/Users/rutgerhuijsmans/Documents/runk-3.0
My database is called runk-3.0-database
The folder looks like this: 

I try to connect to my DB using the following configuration:
import FluentSQLite
import Vapor

/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    /// Register providers first
    try services.register(FluentSQLiteProvider())

    /// Register routes to the router
    let router = EngineRouter.default()
    try routes(router)
    services.register(router, as: Router.self)

    /// Register middleware
    var middlewares = MiddlewareConfig() // Create _empty_ middleware config
    /// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
    middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
    services.register(middlewares)

    let sqlite: SQLiteDatabase?
    do {
        sqlite = try SQLiteDatabase(storage: .file(path: "runk-3.0-database"))
        print("data base connected") // This gets printed

        /// Register the configured SQLite database to the database config.
        var databases = DatabasesConfig()
        databases.add(database: sqlite!, as: .sqlite)
        services.register(databases)

        /// Configure migrations
        var migrations = MigrationConfig()
        migrations.add(model: User.self, database: .sqlite)
        services.register(migrations)
    } catch {
        print("couldn't connect") // This doesn't get printed
    }
}

What am I doing wrong?

A:

As IMike17 explained, your code just creates the new DB file into the Build/Products/Debug or release folder. You have to set full path dynamically as below:
do {
let directory = DirectoryConfig.detect()
let filePath = directory.workDir + "runk-3.0-database"
sqlite = try SQLiteDatabase(storage: .file(path: filePath)) 
......

