Skip to content

Commit

Permalink
Add Concurrency extensions for SQLKit. Not much needed here! (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne authored Nov 20, 2021
1 parent 8587674 commit dff8aba
Show file tree
Hide file tree
Showing 4 changed files with 827 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/SQLKit/Concurrency/SQLDatabase+Concurrency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if compiler(>=5.5) && canImport(_Concurrency)
import NIOCore

@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
public extension SQLDatabase {
func execute(sql query: SQLExpression, _ onRow: @escaping (SQLRow) -> ()) async throws -> Void {
try await self.execute(sql: query, onRow).get()
}
}

#endif
11 changes: 11 additions & 0 deletions Sources/SQLKit/Concurrency/SQLQueryBuilder+Concurrency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if compiler(>=5.5) && canImport(_Concurrency)
import NIOCore

@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
public extension SQLQueryBuilder {
func run() async throws -> Void {
return try await self.run().get()
}
}

#endif
31 changes: 31 additions & 0 deletions Sources/SQLKit/Concurrency/SQLQueryFetcher+Concurrency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if compiler(>=5.5) && canImport(_Concurrency)
import NIOCore

@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
public extension SQLQueryFetcher {
func first<D>(decoding: D.Type) async throws -> D? where D: Decodable {
return try await self.first(decoding: D.self).get()
}

func first() async throws -> SQLRow? {
return try await self.first().get()
}

func all<D>(decoding: D.Type) async throws -> [D] where D: Decodable {
return try await self.all(decoding: D.self).get()
}

func all() async throws -> [SQLRow] {
return try await self.all().get()
}

func run<D>(decoding: D.Type, _ handler: @escaping (Result<D, Error>) -> ()) async throws -> Void where D: Decodable {
return try await self.run(decoding: D.self, handler).get()
}

func run(_ handler: @escaping (SQLRow) -> ()) async throws -> Void {
return try await self.run(handler).get()
}
}

#endif
Loading

0 comments on commit dff8aba

Please sign in to comment.