-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Point to async/await dependencies * Add async pagination function * Add async APIs dfor sessions * Add async sessions * Add async versions of migrate and revert * Fix warning for Page Content conformance * Fix redundant conformance * Depend on FluentKit release * AsyncResponseEncodable is available everywhere now * Use release of Vapor
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Sources/Fluent/Concurrency/FluentProvider+Concurrency.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#if compiler(>=5.5) && canImport(_Concurrency) | ||
import NIOCore | ||
import Vapor | ||
|
||
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) | ||
extension Application { | ||
/// Automatically runs forward migrations without confirmation. | ||
/// This can be triggered by passing `--auto-migrate` flag. | ||
public func autoMigrate() async throws { | ||
try await self.migrator.setupIfNeeded().flatMap { | ||
self.migrator.prepareBatch() | ||
}.get() | ||
} | ||
|
||
/// Automatically runs reverse migrations without confirmation. | ||
/// This can be triggered by passing `--auto-revert` during boot. | ||
public func autoRevert() async throws { | ||
try await self.migrator.setupIfNeeded().flatMap { | ||
self.migrator.revertAllBatches() | ||
}.get() | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#if compiler(>=5.5) && canImport(_Concurrency) | ||
import NIOCore | ||
import Vapor | ||
|
||
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) | ||
extension QueryBuilder { | ||
public func paginate( | ||
for request: Request | ||
) async throws -> Page<Model> { | ||
let page = try request.query.decode(PageRequest.self) | ||
return try await self.paginate(page) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if compiler(>=5.5) && canImport(_Concurrency) | ||
import NIOCore | ||
import Vapor | ||
|
||
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) | ||
extension Model where Self: SessionAuthenticatable, Self.SessionID == Self.IDValue { | ||
public static func asyncSessionAuthenticator( | ||
_ databaseID: DatabaseID? = nil | ||
) -> AsyncAuthenticator { | ||
AsyncDatabaseSessionAuthenticator<Self>(databaseID: databaseID) | ||
} | ||
} | ||
|
||
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) | ||
private struct AsyncDatabaseSessionAuthenticator<User>: AsyncSessionAuthenticator | ||
where User: SessionAuthenticatable, User: Model, User.SessionID == User.IDValue | ||
{ | ||
let databaseID: DatabaseID? | ||
|
||
func authenticate(sessionID: User.SessionID, for request: Request) async throws { | ||
if let user = try await User.find(sessionID, on: request.db(self.databaseID)) { | ||
request.auth.login(user) | ||
} | ||
} | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters