Slick 2.0.0-M3 table definition - clarification on the tag attribute

家住魔仙堡 提交于 2019-12-08 15:55:42

问题


I'm working on migrating to slick 2 but I've come across a class that I can't seem to find anywhere.

package learningSlick

import scala.slick.driver.MySQLDriver.simple._

case class Supplier( snum: String, sname: String, status: Int, city: String )

class Suppliers(tag: Option[String]) extends Table[Supplier](tag, "suppliers") {
  def snum  = column[String]("snum")
  def sname = column[String]("sname")
  def status   = column[Int]("status")
  def city     = column[String]("city")
  def * = snum ~ sname ~ status ~ city <> (Supplier, Supplier.unapply _)
}

The following is the code from the tutorial:

import scala.slick.driver.PostgresDriver.simple._

class Suppliers(tag: Tag) extends Table[(String, String, Int, String)](tag, "suppliers") {
    def    snum = column[String]("snum")
    def sname = column[String]("sname")
    def status = column[Int]("status")
    def city = column[String]("city")
    def * = (snum, sname, status, city) 
}

In the definition for Table it says that the Tag is of type Option[String] however in a tutorial I'm going through it just uses a type of Tag. I'm looking for which package this is coming from.


回答1:


Checking the definition of Table we can see that it's of type Tag: Table definition Don't know where you read or found that it's of type Option[String].

Clicking on Tag brings up the Tag definition: Tag definition

So to answer your question it's coming from the scala.slick.lifted package.

You won't be needing to actually create a Tag, because you query with the val suppliers = TableQuery[Suppliers] construct, which takes care of all the Tag related stuff.



来源:https://stackoverflow.com/questions/20599438/slick-2-0-0-m3-table-definition-clarification-on-the-tag-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!