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

calasql-query_2.13.0.1.9.source-code.Column.scala Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
package scalasql.query

import scalasql.core.{Context, Expr, SqlStr, TypeMapper}
import scalasql.core.SqlStr.SqlStringSyntax

/**
 * A variant of [[Expr]] representing a raw table column; allows assignment in updates
 * and inserts
 */
class Column[T](tableRef: TableRef, val name: String)(implicit val mappedType: TypeMapper[T])
    extends Expr[T] {
  def :=(v: Expr[T]) = Column.Assignment(this, v)

  def renderToSql0(implicit ctx: Context) = {
    val suffix = SqlStr.raw(ctx.config.columnNameMapper(name))
    ctx.fromNaming.get(tableRef) match {
      case Some("") => suffix
      case Some(s) => SqlStr.raw(s) + sql".$suffix"
      case None =>
        sql"SCALASQL_MISSING_TABLE_${SqlStr.raw(Table.name(tableRef.value))}.$suffix"
    }
  }
}
object Column {
  case class Assignment[T](column: Column[T], value: Expr[T])
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy