@@ -11,6 +11,7 @@ import doobie.free.connection.ConnectionIO
11
11
import doobie .free .preparedstatement .PreparedStatementIO
12
12
import doobie .free .resultset .ResultSetIO
13
13
import doobie .free .{connection as IFC , preparedstatement as IFPS }
14
+ import doobie .hi .connection .PreparedExecutionWithResultSet
14
15
import doobie .hi .{connection as IHC , preparedstatement as IHPS , resultset as IHRS }
15
16
import doobie .util .MultiVersionTypeSupport .=:=
16
17
import doobie .util .analysis .Analysis
@@ -20,8 +21,6 @@ import doobie.util.log.{LoggingInfo, Parameters}
20
21
import doobie .util .pos .Pos
21
22
import fs2 .Stream
22
23
23
- import java .sql .{PreparedStatement , ResultSet }
24
-
25
24
/** Module defining queries parameterized by input and output types. */
26
25
object query {
27
26
@@ -114,9 +113,8 @@ object query {
114
113
def toMap [K , V ](a : A )(implicit ev : B =:= (K , V ), f : FactoryCompat [(K , V ), Map [K , V ]]): ConnectionIO [Map [K , V ]] =
115
114
toConnectionIO(a, IHRS .buildPair[Map , K , V ](f, read.map(ev)))
116
115
117
- /**
118
- * Just like `toMap` but allowing to alter `PreparedExecution`.
119
- */
116
+ /** Just like `toMap` but allowing to alter `PreparedExecution`.
117
+ */
120
118
def toMapAlteringExecution [K , V ](a : A , fn : PreparedExecutionUpdate [Map [K , V ]])(implicit
121
119
ev : B =:= (K , V ),
122
120
f : FactoryCompat [(K , V ), Map [K , V ]]
@@ -153,14 +151,22 @@ object query {
153
151
toConnectionIO(a, IHRS .nel[B ])
154
152
155
153
private def toConnectionIO [C ](a : A , rsio : ResultSetIO [C ]): ConnectionIO [C ] =
156
- PreparedExecution ( sql, a, rsio).execute( mkLoggingInfo(a))
154
+ IHC .executionWithResultSet(preparedExecution( sql, a, rsio), mkLoggingInfo(a))
157
155
158
156
private def toConnectionIOAlteringExecution [C ](
159
157
a : A ,
160
158
rsio : ResultSetIO [C ],
161
159
fn : PreparedExecutionUpdate [C ]
162
160
): ConnectionIO [C ] =
163
- fn(PreparedExecution (sql, a, rsio)).execute(mkLoggingInfo(a))
161
+ IHC .executionWithResultSet(fn(preparedExecution(sql, a, rsio)), mkLoggingInfo(a))
162
+
163
+ private def preparedExecution [C ](sql : String , a : A , rsio : ResultSetIO [C ]): PreparedExecutionWithResultSet [C ] =
164
+ PreparedExecutionWithResultSet (
165
+ create = IFC .prepareStatement(sql),
166
+ prep = IHPS .set(a),
167
+ exec = IFPS .executeQuery,
168
+ process = rsio
169
+ )
164
170
165
171
private def mkLoggingInfo (a : A ): LoggingInfo =
166
172
LoggingInfo (
@@ -258,32 +264,7 @@ object query {
258
264
259
265
}
260
266
261
- type PreparedExecutionUpdate [A ] = PreparedExecution [A ] => PreparedExecution [A ]
262
-
263
- final case class PreparedExecution [C ](
264
- create : ConnectionIO [PreparedStatement ],
265
- prep : PreparedStatementIO [Unit ],
266
- exec : PreparedStatementIO [ResultSet ],
267
- process : ResultSetIO [C ]
268
- ) { ctx =>
269
- private [util] def execute (loggingInfo : LoggingInfo ) = IHC .executeWithResultSet(
270
- create = ctx.create,
271
- prep = ctx.prep,
272
- exec = ctx.exec,
273
- process = ctx.process,
274
- loggingInfo = loggingInfo
275
- )
276
- }
277
-
278
- private object PreparedExecution {
279
- def apply [C , A ](sql : String , a : A , rsio : ResultSetIO [C ])(implicit w : Write [A ]): PreparedExecution [C ] =
280
- PreparedExecution (
281
- create = IFC .prepareStatement(sql),
282
- prep = IHPS .set(a),
283
- exec = IFPS .executeQuery,
284
- process = rsio
285
- )
286
- }
267
+ type PreparedExecutionUpdate [A ] = PreparedExecutionWithResultSet [A ] => PreparedExecutionWithResultSet [A ]
287
268
288
269
/** An abstract query closed over its input arguments and yielding values of type `B`, without a specified
289
270
* disposition. Methods provided on `[[Query0 ]]` allow the query to be interpreted as a stream or program in
0 commit comments