Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinitialize Driver #175

Merged
merged 2 commits into from Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/FluentKit/Database/Databases.swift
Expand Up @@ -108,6 +108,21 @@ public final class Databases {
return driver.makeDatabase(with: context)
}

public func reinitialize(_ id: DatabaseID? = nil) {
self.lock.lock()
defer { self.lock.unlock() }

guard
let driver = self.drivers[id ?? self.getDefaultID()],
let configuration = self.configurations[id ?? self.getDefaultID()]
else {
fatalError("You can't reinitialize something that wasn't initialized in the first place.")
}

driver.shutdown()
self.drivers[id ?? self.getDefaultID()] = configuration.makeDriver(for: self)
}

public func shutdown() {
self.lock.lock()
defer { self.lock.unlock() }
Expand Down