Skip to content

Instantly share code, notes, and snippets.

@joscdk
Last active June 8, 2018 09:24
Show Gist options
  • Save joscdk/ab3183a558b18a128dc7258a0f3cdaff to your computer and use it in GitHub Desktop.
Save joscdk/ab3183a558b18a128dc7258a0f3cdaff to your computer and use it in GitHub Desktop.
var databases = DatabasesConfig()
let databaseConfig: PostgreSQLDatabaseConfig
if let url = Environment.get("DB_POSTGRESQL") {
    databaseConfig = try PostgreSQLDatabaseConfig(url: url)
} else {
    // Local configuration
    let hostname = "localhost"
    let username = "vapor"
    let password = "password"
    let database = "vapor"
    databaseConfig = PostgreSQLDatabaseConfig(
        hostname: hostname,
        username: username,
        database: database,
        password: password
    )
}
let database = PostgreSQLDatabase(config: databaseConfig)
databases.add(database: database, as: .psql)
services.register(databases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment