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

anorm.NamedParameter.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 
 */

package anorm

/** Applied named parameter. */
final case class NamedParameter(name: String, value: ParameterValue) {
  lazy val tupled: (String, ParameterValue) = (name, value)
}

/**
 * Companion object for applied named parameter.
 *
 * @define namedWithString Conversion to use tuple, with first element being name of parameter as string.
 * @define namedWithSymbol Conversion to use tuple, with first element being symbolic name or parameter.
 */
object NamedParameter {
  import scala.language.implicitConversions

  /**
   * $namedWithString
   *
   * {{{
   * import anorm.{ NamedParameter, ParameterValue }
   *
   * def foo(pv: ParameterValue): NamedParameter = "name" -> pv
   * }}}
   */
  implicit def namedWithString(t: (String, ParameterValue)): NamedParameter = NamedParameter(t._1, t._2)

  /**
   * $namedWithString
   *
   * {{{
   * import anorm.NamedParameter
   *
   * val p: NamedParameter = "name" -> 1L
   * }}}
   */
  implicit def namedWithString[V](t: (String, V))(implicit c: ToParameterValue[V]): NamedParameter =
    NamedParameter(t._1, c(t._2))

  @deprecated("Use `string` based in `ToParameterValue`", "2.5.4")
  def string[V](t: (String, V))(implicit c: V => ParameterValue): NamedParameter = NamedParameter(t._1, c(t._2))

  /**
   * $namedWithSymbol
   */
  @deprecated(message = "Symbol is deprecated", since = "2.7.0")
  implicit def namedWithSymbol(t: (Symbol, ParameterValue)): NamedParameter =
    NamedParameter(t._1.name, t._2)

  /**
   * $namedWithSymbol
   */
  @deprecated(message = "Symbol is deprecated", since = "2.7.0")
  implicit def namedWithSymbol[V](t: (Symbol, V))(implicit c: ToParameterValue[V]): NamedParameter =
    NamedParameter(t._1.name, c(t._2))

  @deprecated("Use `string` based in `ToParameterValue`", "2.5.4")
  def symbol[V](t: (Symbol, V))(implicit c: V => ParameterValue): NamedParameter = NamedParameter(t._1.name, c(t._2))

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy