【发布时间】:2014-02-22 21:04:40
【问题描述】:
我发现了很多关于“旧”AutoInc 功能如何工作的旧帖子,但几乎没有关于新 AutoInc 功能如何实际工作的帖子。
使用 User 和 Picture 定义了两个私有 AutoInc 函数:
private val picturesAutoInc = pictures
returning pictures.map(_.id) into { case (p, id) => p.copy(id = id) }
private val usersAutoInc = users.map(u => (u.name, u.pictureId))
returning users.map(_.id) into {
case (_, id) => id
}
我在http://slick.typesafe.com/doc/2.0.0/queries.html#inserting上找到了returning方法
但是这个into 函数是什么?它有什么作用?它包含什么?
这是我的课,我应该如何编写自己的 autoInc?
case class Label (id: Option[Int] = None, tag_name: String)
class Labels (tag: Tag) extends Table[Label](tag, "Labels") {
def id = column[Option[Int]]("TAG_ID", O.PrimaryKey, O.AutoInc)
def tag_name = column[String]("TAG_NAME")
def * = (id, tag_name) <> (Label.tupled, Label.unapply _)
}
【问题讨论】: