Skip to content

Commit

Permalink
using expandBatchActionNew and removes old expandBatchAction
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano committed Jul 29, 2023
1 parent a5fb2b1 commit c0dd438
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions quill-core/src/main/scala/io/getquill/context/ActionMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings {
translateBatchQueryPrettyPrint(quoted, q"false")

def translateBatchQueryPrettyPrint(quoted: Tree, prettyPrint: Tree): Tree =
expandBatchAction(quoted) { case (batch, param, expanded) =>
q"""
expandBatchActionNew(quoted, false) {
case (batch, param, expanded, injectableLiftList, idiomNamingOriginalAstVars, idiomContext, canDoBatch) =>
q"""
..${EnableReflectiveCalls(c)}
${c.prefix}.translateBatchQuery(
$batch.map { $param =>
val (idiomContext, expanded) = $expanded
val expanded = $expanded
(expanded.string, expanded.prepare)
}.groupBy(_._1).map {
case (string, items) =>
Expand Down Expand Up @@ -333,30 +334,6 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings {
})
"""

def expandBatchAction(quoted: Tree)(call: (Tree, Tree, Tree) => Tree): Tree =
BetaReduction(extractAst(quoted)) match {
case totalAst @ Foreach(lift: Lift, alias, body) =>
val batch = lift.value.asInstanceOf[Tree]
val batchItemType = batch.tpe.typeArgs.head
c.typecheck(q"(value: $batchItemType) => value") match {
case q"($param) => $value" =>
val nestedLift =
lift match {
case ScalarQueryLift(name, batch: Tree, encoder: Tree, quat) =>
ScalarValueLift("value", External.Source.UnparsedProperty("value"), value, encoder, quat)
case CaseClassQueryLift(name, batch: Tree, quat) =>
CaseClassValueLift("value", "value", value, quat)
}
val (ast, _) = reifyLiftings(BetaReduction(body, alias -> nestedLift))
val expanded = expand(ast, Quat.Unknown)
c.untypecheck {
call(batch, param, expanded)
}
}
case other =>
c.fail(s"Batch actions must be static quotations. Found: '$other'")
}

def prepareAction(quoted: Tree): Tree =
c.untypecheck {
q"""
Expand Down

0 comments on commit c0dd438

Please sign in to comment.