All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getquill.sources.ExtractEntityAndInsertAction.scala Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
package io.getquill.sources

import io.getquill.ast._

case class EntityAndInsertAction(entity: Option[Entity], insert: Option[Insert])

case class ExtractEntityAndInsertAction(state: EntityAndInsertAction) extends StatefulTransformer[EntityAndInsertAction] {

  override def apply(e: Query): (Query, StatefulTransformer[EntityAndInsertAction]) =
    e match {
      case e: Entity =>
        (e, ExtractEntityAndInsertAction(state.copy(entity = Some(e))))
      case other => super.apply(other)
    }

  override def apply(e: Action): (Action, StatefulTransformer[EntityAndInsertAction]) =
    e match {
      case e @ Insert(a) =>
        val (at, att) = apply(a)
        (Insert(at), ExtractEntityAndInsertAction(att.state.copy(insert = Some(e))))
      case other => super.apply(other)
    }
}

object ExtractEntityAndInsertAction {
  def apply(ast: Ast) = new ExtractEntityAndInsertAction(EntityAndInsertAction(None, None))(ast) match {
    case (_, s) => (s.state.entity, s.state.insert)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy