@@ -11,21 +11,21 @@ public enum Queries {
1111 /// Allows for the erasing of the database so a query can be
1212 /// passed around and be able to be executed without
1313 /// having the caller worry about by what.
14- public struct WithDatabase < Base: Queryable > : Query {
14+ public struct WithDatabase < Base: Queryable > : Queryable {
1515 /// The original query that requires a database
1616 let base : Base
1717 /// The database to execute the query in
18- let database : any Database
18+ let database : Base . DB
1919
2020 public var transactionKind : TransactionKind {
2121 return base. transactionKind
2222 }
2323
2424 public func execute(
25- with input: Base . Input
25+ with input: Base . Input ,
26+ in _: ( )
2627 ) async throws -> Base . Output {
27- let tx = try await database. begin ( transactionKind)
28- return try execute ( with: input, tx: tx)
28+ return try await base. execute ( with: input, in: database)
2929 }
3030
3131 public func execute(
@@ -34,23 +34,10 @@ public enum Queries {
3434 ) throws -> Base . Output {
3535 return try base. execute ( with: input, tx: tx)
3636 }
37-
38- public func observe(
39- with input: Input ,
40- handle: @Sendable @escaping ( Output ) -> Void ,
41- cancelled: @Sendable @escaping ( ) -> Void
42- ) -> QueryObservation < Input , Output > {
43- return base. observe (
44- with: input,
45- in: database,
46- handle: handle,
47- cancelled: cancelled
48- )
49- }
5037 }
5138
5239 /// Applies a transform to the queries result
53- public struct Map < Base: Query , Output: Sendable > : Query {
40+ public struct Map < Base: Queryable , Output: Sendable > : Queryable {
5441 /// The upstream query to transform
5542 let base : Base
5643 /// The transform to apply to the output
@@ -60,23 +47,13 @@ public enum Queries {
6047 return base. transactionKind
6148 }
6249
63- public func execute( with input: Base . Input ) async throws -> Output {
64- return try await transform ( base. execute ( with: input) )
65- }
66-
67- public func observe(
68- with input: Input ,
69- handle: @Sendable @escaping ( Output ) -> Void ,
70- cancelled: @Sendable @escaping ( ) -> Void
71- ) -> QueryObservation < Input , Output > {
72- fatalError ( )
73- // return base.observe(
74- // with: input,
75- // handle: { handle(transform($0)) },
76- // cancelled: cancelled
77- // )
50+ public func execute(
51+ with input: Base . Input ,
52+ in database: Base . DB
53+ ) async throws -> Output {
54+ return try await transform ( base. execute ( with: input, in: database) )
7855 }
79-
56+
8057 public func execute(
8158 with input: Base . Input ,
8259 tx: borrowing Transaction
@@ -86,8 +63,8 @@ public enum Queries {
8663 }
8764
8865 /// Applies a transform to the queries result
89- public struct Just < Input, Output, DB > : Query
90- where Input: Sendable , Output: Sendable , DB : Database
66+ public struct Just < Input, Output> : Queryable
67+ where Input: Sendable , Output: Sendable
9168 {
9269 let output : Output
9370
@@ -100,7 +77,8 @@ public enum Queries {
10077 }
10178
10279 public func execute(
103- with input: Input
80+ with input: Input ,
81+ in _: ( )
10482 ) async throws -> Output {
10583 return output
10684 }
@@ -111,20 +89,6 @@ public enum Queries {
11189 ) throws -> Output {
11290 return output
11391 }
114-
115- public func observe(
116- with input: Input ,
117- handle: @Sendable @escaping ( Output ) -> Void ,
118- cancelled: @Sendable @escaping ( ) -> Void
119- ) -> QueryObservation < Input , Output > {
120- QueryObservation < Input , Output > (
121- query: self ,
122- input: input,
123- database: ErasedDatabase . shared,
124- handle: handle,
125- cancelled: cancelled
126- )
127- }
12892 }
12993
13094 public struct Then < First, Second> : Queryable
@@ -134,6 +98,8 @@ public enum Queries {
13498 let first : First
13599 let second : Second
136100
101+ public typealias DB = any Database
102+
137103 public var transactionKind : TransactionKind {
138104 return max ( first. transactionKind, second. transactionKind)
139105 }
@@ -150,7 +116,7 @@ public enum Queries {
150116}
151117
152118public extension Queryable {
153- func with( database: any Database ) -> Queries . WithDatabase < Self > {
119+ func with( database: DB ) -> Queries . WithDatabase < Self > {
154120 return Queries . WithDatabase ( base: self , database: database)
155121 }
156122
@@ -178,5 +144,3 @@ public extension Queryable {
178144 }
179145 }
180146}
181-
182-
0 commit comments