Skip to content

Commit

Permalink
Merge pull request #412 from qutheory/database-provider-patch
Browse files Browse the repository at this point in the history
update database provider
  • Loading branch information
loganwright committed Jun 30, 2016
2 parents 3be3d45 + 4d734c0 commit f703832
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/Vapor/Core/Application.swift
Expand Up @@ -144,6 +144,7 @@ public class Application {
var hashProvided: Hash? = hash
var consoleProvided: Console? = console
var clientProvided: Client.Type? = clientType
var databaseProvided: DatabaseDriver? = database

for provider in providers {
// TODO: Warn if multiple providers attempt to add server
Expand All @@ -153,6 +154,7 @@ public class Application {
hashProvided = provider.hash ?? hashProvided
consoleProvided = provider.console ?? consoleProvided
clientProvided = provider.client ?? clientProvided
databaseProvided = provider.database ?? databaseProvided
}

let arguments = arguments ?? NSProcessInfo.processInfo().arguments
Expand Down Expand Up @@ -205,8 +207,14 @@ public class Application {

self.preparations = preparations

if let driver = database {
self.database = Database(driver: driver)
if let driver = databaseProvided {
let database = Database(driver: driver)
for preparation in preparations {
if let model = preparation as? Model.Type {
model.database = database
}
}
self.database = database
} else {
self.database = nil
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/Vapor/Core/Provider.swift
Expand Up @@ -62,6 +62,8 @@ public protocol Provider {
outgoing web request operations
*/
var client: Client.Type? { get }

var database: DatabaseDriver? { get }
}

extension Provider {
Expand All @@ -88,4 +90,8 @@ extension Provider {
public var client: Client.Type? {
return nil
}

public var database: DatabaseDriver? {
return nil
}
}

0 comments on commit f703832

Please sign in to comment.