在Slick官方文档中描述:连接后台数据库后,需要通过定义Projection,即def * 来进行具体库表列column的选择和排序。通过Projection我们可以选择库表中部分列、也可以增加一些自定义列computed column。具体来说Projection提供了数据库表列与Scala值的对应。例如def * = (column1,column2)把库表的column1和column2与(Int,String)对应,column1[Int],column2[String]。也可以说是与定义column的类参数进行对应。从Slick源代码中我们可以找到Projection定义:
abstract class AbstractTable[T](val tableTag: Tag, val schemaName: Option[String], val tableName: String) extends Rep[T] { /** The client-side type of the table as defined by its * projection */ type TableElementType ... /** The * projection of the table used as default for queries and inserts. * Should include all columns as a tuple, HList or custom shape and optionally * map them to a custom entity type using the <> operator. * The `ProvenShape` return type ensures that * there is a `Shape` available for translating between the `Column`-based * type in * and the client-side type without `Column` in the table's type * parameter. */ def * : ProvenShape[T] ... }
网友评论