diff --git a/quill-cassandra-pekko/src/main/scala/io/getquill/CassandraPekkoContext.scala b/quill-cassandra-pekko/src/main/scala/io/getquill/CassandraPekkoContext.scala index 1aac5a22a0..ec474b4962 100644 --- a/quill-cassandra-pekko/src/main/scala/io/getquill/CassandraPekkoContext.scala +++ b/quill-cassandra-pekko/src/main/scala/io/getquill/CassandraPekkoContext.scala @@ -94,7 +94,7 @@ class CassandraPekkoContext[+N <: NamingStrategy]( groups: List[BatchGroup] )(info: ExecutionInfo, dc: Runner)(implicit executionContext: ExecutionContext): Result[RunBatchActionResult] = Future.sequence { - groups.flatMap { case BatchGroup(cql, prepare) => + groups.flatMap { case BatchGroup(cql, prepare, _) => prepare.map(executeAction(cql, _)(info, dc)) } } diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala index fbd88fd354..528f536509 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala @@ -153,7 +153,7 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N) env <- ZIO.service[CassandraZioSession] _ <- { val batchGroups = - groups.flatMap { case BatchGroup(cql, prepare) => + groups.flatMap { case BatchGroup(cql, prepare, _) => prepare .map(prep => executeAction(cql, prep)(info, dc).provideEnvironment(ZEnvironment(env))) } diff --git a/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala b/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala index 2df23b8625..996ef13ae7 100644 --- a/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala @@ -65,7 +65,7 @@ class CassandraAsyncContext[+N <: NamingStrategy]( groups: List[BatchGroup] )(info: ExecutionInfo, dc: Runner)(implicit executionContext: ExecutionContext): Result[RunBatchActionResult] = Future.sequence { - groups.flatMap { case BatchGroup(cql, prepare) => + groups.flatMap { case BatchGroup(cql, prepare, _) => prepare.map(executeAction(cql, _)(info, dc)) } }.map(_ => ()) diff --git a/quill-cassandra/src/main/scala/io/getquill/CassandraSyncContext.scala b/quill-cassandra/src/main/scala/io/getquill/CassandraSyncContext.scala index a858b2bc4b..3c4da83a8a 100644 --- a/quill-cassandra/src/main/scala/io/getquill/CassandraSyncContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/CassandraSyncContext.scala @@ -56,7 +56,7 @@ class CassandraSyncContext[+N <: NamingStrategy]( } def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): Unit = - groups.foreach { case BatchGroup(cql, prepare) => + groups.foreach { case BatchGroup(cql, prepare, _) => prepare.foreach(executeAction(cql, _)(info, dc)) } } diff --git a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala index 63dc3d54ee..175d8febde 100644 --- a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala @@ -135,7 +135,7 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = Future { BatchActionMirror( - groups.map { case BatchGroup(string, prepare) => + groups.map { case BatchGroup(string, prepare, _) => (string, prepare.map(_(Row(), session)._2)) }, executionInfo diff --git a/quill-core/src/main/scala/io/getquill/MirrorContext.scala b/quill-core/src/main/scala/io/getquill/MirrorContext.scala index 291a94ad2f..fd4ab569ae 100644 --- a/quill-core/src/main/scala/io/getquill/MirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/MirrorContext.scala @@ -128,7 +128,7 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner) = BatchActionMirror( - groups.map { case BatchGroup(string, prepare) => + groups.map { case BatchGroup(string, prepare, _) => (string, prepare.map(_(Row(), session)._2)) }, info @@ -151,7 +151,7 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner) = (session: Session) => - groups.flatMap { case BatchGroup(string, prepare) => + groups.flatMap { case BatchGroup(string, prepare, _) => prepare.map(_(Row(), session)._2) } diff --git a/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala b/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala index 94424e4746..139d7b5ad5 100644 --- a/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala +++ b/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala @@ -18,7 +18,7 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings { def translateQuery(quoted: Tree): Tree = translateQueryPrettyPrint(quoted, q"false") - def translateQueryPrettyPrint(quoted: Tree, prettyPrint: Tree): Tree = { + def translateQueryPrettyPrint(quoted: Tree, options: Tree): Tree = { val expanded = expand(extractAst(quoted), inferQuat(quoted.tpe)) c.untypecheck { q""" @@ -26,8 +26,7 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings { val (idiomContext, expanded) = $expanded ${c.prefix}.translateQuery( expanded.string, - expanded.prepare, - prettyPrint = ${prettyPrint} + options = ${options} )(io.getquill.context.ExecutionInfo.unknown, ()) """ } @@ -36,7 +35,8 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings { def translateBatchQuery(quoted: Tree): Tree = translateBatchQueryPrettyPrint(quoted, q"false") - def translateBatchQueryPrettyPrint(quoted: Tree, prettyPrint: Tree): Tree = + // TODO need to change this to include liftings + def translateBatchQueryPrettyPrint(quoted: Tree, options: Tree): Tree = expandBatchActionNew(quoted, isReturning = false) { case (batch, param, expanded, injectableLiftList, idiomNamingOriginalAstVars, idiomContext, canDoBatch) => q""" @@ -50,12 +50,12 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings { ${c.prefix}.translateBatchQuery( batches.map { subBatch => val expanded = $expanded - (expanded.string, expanded.prepare) + (expanded.string, expanded.prepare, expanded.liftings) }.groupBy(_._1).map { case (string, items) => ${c.prefix}.BatchGroup(string, items.map(_._2).toList) }.toList, - $prettyPrint + $options )(io.getquill.context.ExecutionInfo.unknown, ()) """ } diff --git a/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala b/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala index 0fd95342f1..0510b910ed 100644 --- a/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala +++ b/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala @@ -1,5 +1,6 @@ package io.getquill.context +import io.getquill.ast.ScalarLift import io.getquill.{Action, BatchAction, NamingStrategy, Query, Quoted} import io.getquill.idiom.Idiom @@ -16,34 +17,40 @@ trait ContextVerbTranslate extends ContextTranslateMacro { override def seq[A](list: List[A]): List[A] = list } +case class TranslateOptions( + prettyPrint: Boolean = false, + plugLifts: Boolean = true, + demarcateLifts: Boolean = true +) + trait ContextTranslateMacro extends ContextTranslateProto { this: Context[_ <: Idiom, _ <: NamingStrategy] => - def translate[T](quoted: Quoted[T]): TranslateResult[String] = macro QueryMacro.translateQuery[T] - def translate[T](quoted: Quoted[Query[T]]): TranslateResult[String] = macro QueryMacro.translateQuery[T] - def translate(quoted: Quoted[Action[_]]): TranslateResult[String] = macro ActionMacro.translateQuery - def translate(quoted: Quoted[BatchAction[Action[_]]]): TranslateResult[List[String]] = + def translate[T](quoted: Quoted[T]): String = macro QueryMacro.translateQuery[T] + def translate[T](quoted: Quoted[Query[T]]): String = macro QueryMacro.translateQuery[T] + def translate(quoted: Quoted[Action[_]]): String = macro ActionMacro.translateQuery + def translate(quoted: Quoted[BatchAction[Action[_]]]): List[String] = macro ActionMacro.translateBatchQuery - def translate[T](quoted: Quoted[T], prettyPrint: Boolean): TranslateResult[String] = + def translate[T](quoted: Quoted[T], options: TranslateOptions): TranslateResult[String] = macro QueryMacro.translateQueryPrettyPrint[T] - def translate[T](quoted: Quoted[Query[T]], prettyPrint: Boolean): TranslateResult[String] = + def translate[T](quoted: Quoted[Query[T]], options: TranslateOptions): TranslateResult[String] = macro QueryMacro.translateQueryPrettyPrint[T] - def translate(quoted: Quoted[Action[_]], prettyPrint: Boolean): TranslateResult[String] = + def translate(quoted: Quoted[Action[_]], options: TranslateOptions): TranslateResult[String] = macro ActionMacro.translateQueryPrettyPrint - def translate(quoted: Quoted[BatchAction[Action[_]]], prettyPrint: Boolean): TranslateResult[List[String]] = + def translate(quoted: Quoted[BatchAction[Action[_]]], options: TranslateOptions): TranslateResult[List[String]] = macro ActionMacro.translateBatchQueryPrettyPrint def translateQuery[T]( statement: String, - prepare: Prepare = identityPrepare, - extractor: Extractor[T] = identityExtractor, - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String] - def translateBatchQuery(groups: List[BatchGroup], prettyPrint: Boolean = false)( + lifts: List[ScalarLift] = List(), + options: TranslateOptions + )(executionInfo: ExecutionInfo, dc: Runner): String + + def translateBatchQuery(groups: List[BatchGroup], options: TranslateOptions = TranslateOptions())( executionInfo: ExecutionInfo, dc: Runner - ): TranslateResult[List[String]] + ): List[String] } trait ContextTranslateProto { @@ -58,40 +65,36 @@ trait ContextTranslateProto { def translateQuery[T]( statement: String, - prepare: Prepare = identityPrepare, - extractor: Extractor[T] = identityExtractor, - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String] = - try { - push(prepareParams(statement, prepare)) { params => - val query = - if (params.nonEmpty) { - params.foldLeft(statement) { case (expanded, param) => - expanded.replaceFirst("\\?", param) - } - } else { - statement + liftings: List[ScalarLift] = List(), + options: TranslateOptions = TranslateOptions() + )(executionInfo: ExecutionInfo, dc: Runner): String = + (liftings.nonEmpty, options.plugLifts) match { + case (true, true) => + liftings.foldLeft(statement) { case (expanded, lift) => + expanded.replaceFirst("\\?", if (options.demarcateLifts) s"prep(${lift.value})" else s"${lift.value}") + } + case (true, false) => + var varNum: Int = 0 + val dol = '$' + val numberedQuery = + liftings.foldLeft(statement) { case (expanded, lift) => + val res = expanded.replaceFirst("\\?", s"${dol}${varNum}") + varNum += 1 + res } - - if (prettyPrint) - idiom.format(query) - else - query - } - } catch { - case e: Exception => - wrap("\n" + statement) + numberedQuery + "\n" + liftings.map(lift => s"${dol} = ${lift.value}").mkString("\n") + case _ => + statement } def translateBatchQuery( + // TODO these groups need to have liftings lists groups: List[BatchGroup], - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[List[String]] = - seq { - groups.flatMap { group => - group.prepare.map { prepare => - translateQuery(group.string, prepare, prettyPrint = prettyPrint)(executionInfo, dc) - } + options: TranslateOptions = TranslateOptions() + )(executionInfo: ExecutionInfo, dc: Runner): List[String] = + groups.flatMap { group => + group.prepare.map { _ => + translateQuery(group.string, options = options)(executionInfo, dc) } } diff --git a/quill-core/src/main/scala/io/getquill/context/QueryMacro.scala b/quill-core/src/main/scala/io/getquill/context/QueryMacro.scala index ac2cf6fa2d..480fb65a13 100644 --- a/quill-core/src/main/scala/io/getquill/context/QueryMacro.scala +++ b/quill-core/src/main/scala/io/getquill/context/QueryMacro.scala @@ -14,16 +14,16 @@ class QueryMacro(val c: MacroContext) extends ContextMacro { case object UsesDefaultFetch extends FetchSizeArg case object DoesNotUseFetch extends FetchSizeArg - sealed trait PrettyPrintingArg - case class ExplicitPrettyPrint(tree: Tree) extends PrettyPrintingArg - case object DefaultPrint extends PrettyPrintingArg + sealed trait PrettyPrintingOptions + case class ExplicitOptions(tree: Tree) extends PrettyPrintingOptions + case object DefaultPrint extends PrettyPrintingOptions sealed trait ContextMethod { def name: String } - case class StreamQuery(fetchSizeBehavior: FetchSizeArg) extends ContextMethod { val name = "streamQuery" } - case object ExecuteQuery extends ContextMethod { val name = "executeQuery" } - case object ExecuteQuerySingle extends ContextMethod { val name = "executeQuerySingle" } - case class TranslateQuery(prettyPrintingArg: PrettyPrintingArg) extends ContextMethod { val name = "translateQuery" } - case object PrepareQuery extends ContextMethod { val name = "prepareQuery" } + case class StreamQuery(fetchSizeBehavior: FetchSizeArg) extends ContextMethod { val name = "streamQuery" } + case object ExecuteQuery extends ContextMethod { val name = "executeQuery" } + case object ExecuteQuerySingle extends ContextMethod { val name = "executeQuerySingle" } + case class TranslateQuery(prettyPrintingOpts: PrettyPrintingOptions) extends ContextMethod { val name = "translateQuery" } + case object PrepareQuery extends ContextMethod { val name = "prepareQuery" } def streamQuery[T](quoted: Tree)(implicit t: WeakTypeTag[T]): Tree = expandQuery[T](quoted, StreamQuery(UsesDefaultFetch)) @@ -40,8 +40,8 @@ class QueryMacro(val c: MacroContext) extends ContextMacro { def translateQuery[T](quoted: Tree)(implicit t: WeakTypeTag[T]): Tree = expandQuery[T](quoted, TranslateQuery(DefaultPrint)) - def translateQueryPrettyPrint[T](quoted: Tree, prettyPrint: Tree)(implicit t: WeakTypeTag[T]): Tree = - expandQuery[T](quoted, TranslateQuery(ExplicitPrettyPrint(prettyPrint))) + def translateQueryPrettyPrint[T](quoted: Tree, options: Tree)(implicit t: WeakTypeTag[T]): Tree = + expandQuery[T](quoted, TranslateQuery(ExplicitOptions(options))) def prepareQuery[T](quoted: Tree)(implicit t: WeakTypeTag[T]): Tree = expandQuery[T](quoted, PrepareQuery) @@ -85,22 +85,23 @@ class QueryMacro(val c: MacroContext) extends ContextMacro { (row, session) => $decoder(0, row, session) )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ - case TranslateQuery(ExplicitPrettyPrint(argValue)) => + case TranslateQuery(ExplicitOptions(argValue)) => + // use 'liftings' instead of 'prepare' I.e. the List[ScalarLifts] extracted from the query during Expand q""" ${c.prefix}.${TermName(method.name)}( expanded.string, - expanded.prepare, + expanded.liftings, (row, session) => $decoder(0, row, session), - prettyPrint = ${argValue} + options = ${argValue} )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ case TranslateQuery(DefaultPrint) => q""" ${c.prefix}.${TermName(method.name)}( expanded.string, - expanded.prepare, + expanded.liftings, (row, session) => $decoder(0, row, session), - prettyPrint = false + options = io.getquill.context.TranslateOptions() )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ case PrepareQuery => @@ -167,22 +168,20 @@ class QueryMacro(val c: MacroContext) extends ContextMacro { $meta.extract )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ - case TranslateQuery(ExplicitPrettyPrint(argValue)) => + case TranslateQuery(ExplicitOptions(argValue)) => q""" ${c.prefix}.${TermName(method.name)}( expanded.string, - expanded.prepare, - $meta.extract, - prettyPrint = ${argValue} + expanded.liftings, + options = ${argValue} )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ case TranslateQuery(DefaultPrint) => q""" ${c.prefix}.${TermName(method.name)}( expanded.string, - expanded.prepare, - $meta.extract, - prettyPrint = false + expanded.liftings, + options = io.getquill.context.TranslateOptions() )(io.getquill.context.ExecutionInfo(expanded.executionType, expanded.ast, staticTopLevelQuat), ()) """ case PrepareQuery => diff --git a/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala b/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala index d07f2b5252..113dda2a21 100644 --- a/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala +++ b/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala @@ -169,7 +169,7 @@ trait DoobieContextBase[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] )( info: ExecutionInfo, dc: Runner - ): ConnectionIO[List[Long]] = groups.flatTraverse { case BatchGroup(sql, preps) => + ): ConnectionIO[List[Long]] = groups.flatTraverse { case BatchGroup(sql, preps, _) => HC.prepareStatement(sql) { useConnection { implicit connection => for { diff --git a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala index 254ef984e0..86ed84ba1e 100644 --- a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala +++ b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala @@ -1,6 +1,7 @@ package io.getquill.context import io.getquill.ReturnAction +import io.getquill.ast.ScalarLift trait RowContext { type PrepareRow @@ -10,7 +11,7 @@ trait RowContext { private val _identityExtractor: Extractor[Any] = (rr: ResultRow, _: Session) => rr protected def identityExtractor[T]: Extractor[T] = _identityExtractor.asInstanceOf[Extractor[T]] - case class BatchGroup(string: String, prepare: List[Prepare]) + case class BatchGroup(string: String, prepare: List[Prepare], liftings: List[ScalarLift]) case class BatchGroupReturning(string: String, returningBehavior: ReturnAction, prepare: List[Prepare]) type Prepare = (PrepareRow, Session) => (List[Any], PrepareRow) diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcContext.scala b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcContext.scala index e65c53b6b7..a33fa928bd 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcContext.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcContext.scala @@ -1,5 +1,6 @@ package io.getquill.context.qzio +import io.getquill.ast.ScalarLift import io.getquill.context.ZioJdbc._ import io.getquill.context._ import io.getquill.context.jdbc.JdbcContextTypes @@ -104,22 +105,19 @@ abstract class ZioJdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] override def translateQuery[T]( statement: String, - prepare: Prepare = identityPrepare, - extractor: Extractor[T] = identityExtractor, - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String] = - onConnection(connDelegate.translateQuery[T](statement, prepare, extractor, prettyPrint)(executionInfo, dc)) + liftings: List[ScalarLift] = List(), + options: TranslateOptions = TranslateOptions() + )(executionInfo: ExecutionInfo, dc: Runner): String = + connDelegate.translateQuery[T](statement, liftings, options)(executionInfo, dc) override def translateBatchQuery( groups: List[BatchGroup], - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[List[String]] = - onConnection( - connDelegate.translateBatchQuery( - groups.asInstanceOf[List[ZioJdbcContext.this.connDelegate.BatchGroup]], - prettyPrint - )(executionInfo, dc) - ) + options: TranslateOptions = TranslateOptions() + )(executionInfo: ExecutionInfo, dc: Runner): List[String] = + connDelegate.translateBatchQuery( + groups.asInstanceOf[List[ZioJdbcContext.this.connDelegate.BatchGroup]], + options + )(executionInfo, dc) def streamQuery[T]( fetchSize: Option[Int], diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioPrepareContext.scala b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioPrepareContext.scala index 1490883743..5fbb15e401 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioPrepareContext.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioPrepareContext.scala @@ -55,7 +55,7 @@ trait ZioPrepareContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): PrepareBatchActionResult = ZIO .collectAll[Connection, Throwable, PrepareRow, List] { - val batches = groups.flatMap { case BatchGroup(sql, prepares) => + val batches = groups.flatMap { case BatchGroup(sql, prepares, _) => prepares.map(sql -> _) } batches.map { case (sql, prepare) => diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/jdbczio/QuillBaseContext.scala b/quill-jdbc-zio/src/main/scala/io/getquill/jdbczio/QuillBaseContext.scala index 5d8515db0a..dee7a5d09d 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/jdbczio/QuillBaseContext.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/jdbczio/QuillBaseContext.scala @@ -1,7 +1,8 @@ package io.getquill.jdbczio +import io.getquill.ast.ScalarLift import io.getquill.{NamingStrategy, ReturnAction} -import io.getquill.context.{ContextVerbStream, ExecutionInfo, ProtoContext} +import io.getquill.context.{ContextVerbStream, ExecutionInfo, ProtoContext, TranslateOptions} import io.getquill.context.jdbc.JdbcContextTypes import io.getquill.context.qzio.{ZioContext, ZioJdbcContext, ZioTranslateContext} import io.getquill.context.sql.idiom.SqlIdiom @@ -66,22 +67,19 @@ trait QuillBaseContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] override def translateQuery[T]( statement: String, - prepare: Prepare = identityPrepare, - extractor: Extractor[T] = identityExtractor, - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String] = - onDS(dsDelegate.translateQuery[T](statement, prepare, extractor, prettyPrint)(executionInfo, dc)) + lifts: List[ScalarLift] = List(), + options: TranslateOptions + )(executionInfo: ExecutionInfo, dc: Runner): String = + dsDelegate.translateQuery[T](statement, lifts, options)(executionInfo, dc) override def translateBatchQuery( groups: List[BatchGroup], - prettyPrint: Boolean = false - )(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[List[String]] = - onDS( - dsDelegate.translateBatchQuery( - groups.asInstanceOf[List[QuillBaseContext.this.dsDelegate.BatchGroup]], - prettyPrint - )(executionInfo, dc) - ) + options: TranslateOptions + )(executionInfo: ExecutionInfo, dc: Runner): List[String] = + dsDelegate.translateBatchQuery( + groups.asInstanceOf[List[QuillBaseContext.this.dsDelegate.BatchGroup]], + options + )(executionInfo, dc) def streamQuery[T]( fetchSize: Option[Int], diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala index a717942328..9bb9f1849c 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala @@ -86,7 +86,7 @@ trait JdbcContextVerbExecute[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): Result[List[Long]] = withConnectionWrapped { conn => - groups.flatMap { case BatchGroup(sql, prepare) => + groups.flatMap { case BatchGroup(sql, prepare, _) => val ps = conn.prepareStatement(sql) logger.underlying.debug("Batch: {}", sql) prepare.foreach { f => diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbPrepare.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbPrepare.scala index ca62ec341b..ab038fe382 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbPrepare.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbPrepare.scala @@ -51,7 +51,7 @@ trait JdbcContextVerbPrepare[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] def prepareBatchAction(groups: List[BatchGroup])(executionInfo: ExecutionInfo, dc: Runner): PrepareBatchActionResult = constructPrepareBatchAction { (session: Connection) => seq { - val batches = groups.flatMap { case BatchGroup(sql, prepares) => + val batches = groups.flatMap { case BatchGroup(sql, prepares, _) => prepares.map(sql -> _) } batches.map { case (sql, prepare) => diff --git a/quill-orientdb/src/main/scala/io/getquill/OrientDBSyncContext.scala b/quill-orientdb/src/main/scala/io/getquill/OrientDBSyncContext.scala index 0ca4188ce5..29af31239f 100644 --- a/quill-orientdb/src/main/scala/io/getquill/OrientDBSyncContext.scala +++ b/quill-orientdb/src/main/scala/io/getquill/OrientDBSyncContext.scala @@ -68,7 +68,7 @@ class OrientDBSyncContext[+N <: NamingStrategy]( } def executeBatchAction[T](groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): Unit = - groups.foreach { case BatchGroup(orientQl, prepare) => + groups.foreach { case BatchGroup(orientQl, prepare, _) => prepare.foreach(executeAction(orientQl, _)(info, dc)) }