|
10 | 10 | /// on the original base query type. Erasing to this can allow for |
11 | 11 | /// use of the operators. |
12 | 12 | public struct AnyQuery<Input: Sendable, Output: Sendable>: Query { |
13 | | - let query: any Query<Input, Output> |
14 | | - |
| 13 | + public let transactionKind: Transaction.Kind |
| 14 | + public let connection: any Connection |
| 15 | + public let watchedTables: Set<String> |
| 16 | + private let _execute: @Sendable (Input, borrowing Transaction) throws -> Output |
| 17 | + private let _observe: @Sendable (Input) -> any QueryObservation<Output> |
| 18 | + |
| 19 | + public init( |
| 20 | + transactionKind: Transaction.Kind, |
| 21 | + connection: any Connection, |
| 22 | + watchedTables: Set<String>, |
| 23 | + execute: @Sendable @escaping (Input, borrowing Transaction) throws -> Output, |
| 24 | + observe: @Sendable @escaping (Input) -> any QueryObservation<Output> |
| 25 | + ) { |
| 26 | + self.transactionKind = transactionKind |
| 27 | + self.connection = connection |
| 28 | + self.watchedTables = watchedTables |
| 29 | + self._execute = execute |
| 30 | + self._observe = observe |
| 31 | + } |
| 32 | + |
15 | 33 | public init(_ query: any Query<Input, Output>) { |
16 | | - self.query = query |
| 34 | + self = AnyQuery( |
| 35 | + transactionKind: query.transactionKind, |
| 36 | + connection: query.connection, |
| 37 | + watchedTables: query.watchedTables, |
| 38 | + execute: { try query.execute(with: $0, tx: $1) }, |
| 39 | + observe: { query.observe(with: $0) } |
| 40 | + ) |
17 | 41 | } |
18 | | - |
19 | | - public func execute(with input: Input) async throws -> Output { |
20 | | - try await query.execute(with: input) |
| 42 | + |
| 43 | + public func execute(with input: Input, tx: borrowing Transaction) throws -> Output { |
| 44 | + try _execute(input, tx) |
21 | 45 | } |
22 | 46 |
|
23 | 47 | public func observe(with input: Input) -> any QueryObservation<Output> { |
24 | | - query.observe(with: input) |
| 48 | + _observe(input) |
25 | 49 | } |
26 | 50 | } |
27 | 51 |
|
|
0 commit comments