在Slick官方文檔中描述:連接后臺數(shù)據(jù)庫后,需要通過定義Projection,即def * 來進行具體庫表列column的選擇和排序。通過Projection我們可以選擇庫表中部分列、也可以增加一些自定義列computed column。具體來說Projection提供了數(shù)據(jù)庫表列與Scala值的對應(yīng)。例如def * = (column1,column2)把庫表的column1和column2與(Int,String)對應(yīng),column1[Int],column2[String]。也可以說是與定義column的類參數(shù)進行對應(yīng)。從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] ... }
延伸閱讀
學(xué)習(xí)是年輕人改變自己的最好方式