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

scalikejdbc.autoNamedValues.scala Maven / Gradle / Ivy

There is a newer version: 3.2.4
Show newest version
package scalikejdbc

import scala.language.experimental.macros
import scalikejdbc.MacroCompatible.Context

object autoNamedValues {
  def apply_impl[E: c.WeakTypeTag](c: Context)(entity: c.Expr[E], column: c.Expr[ColumnName[E]], excludes: c.Expr[String]*): c.Expr[Map[SQLSyntax, ParameterBinder]] = {
    import c.universe._

    val toMapParams: List[c.universe.Tree] = EntityUtil.constructorParams[E](c)("autoNamedValues", excludes: _*).map { field =>
      val fieldName = field.name.toTermName

      q"$column.$fieldName -> $entity.$fieldName"
    }

    c.Expr[Map[SQLSyntax, ParameterBinder]](q"_root_.scala.collection.immutable.Map(..$toMapParams)")
  }

  def debug_impl[E: c.WeakTypeTag](c: Context)(entity: c.Expr[E], column: c.Expr[ColumnName[E]], excludes: c.Expr[String]*): c.Expr[Map[SQLSyntax, ParameterBinder]] = {
    val expr = apply_impl[E](c)(entity, column, excludes: _*)
    println(expr.tree)
    expr
  }

  def debug[E](entity: E, column: ColumnName[E], excludes: String*): Map[SQLSyntax, ParameterBinder] = macro debug_impl[E]

  def apply[E](entity: E, column: ColumnName[E], excludes: String*): Map[SQLSyntax, ParameterBinder] = macro apply_impl[E]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy