【发布时间】:2013-12-31 13:27:38
【问题描述】:
我目前正在编写 Slick 代码以针对具有两个表 > 22 列的旧模式。我如何use the new HList code?在 Scala 2.10.3 下,我的 2.0-M3 在其他方面工作正常。 这是我目前在案例类/元组中使用的语法。我会怎么做use the new HLists mentioned in the docs?
case class Joiner(
id: Int,
name: Option[String],
contact: Option[String]
)
class Joiners(tag: Tag) extends Table[Joiner](tag, "joiner") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc, O.DBType("int(11)"))
def name = column[Option[String]]("name", O.DBType("varchar(255)"))
def contact = column[Option[String]]("contact", O.DBType("text"))
def * = (id, name.?, contact.?) <> (Joiner.tupled, Joiner.unapply)
}
val joiners = TableQuery[Joiners]
我在示例中看不到任何内容,仅在新更新的文档中简要提及。我是 Scala 和 Slick 的新手。
【问题讨论】:
-
最初我使用的是 O.Nullable 而不是 Option[String]。根据 Vogt 先生的建议进行了更正。
-
抱歉,我收到一条消息说我的 Google 网上论坛帖子被拒绝了,所以我认为它不起作用。
-
注意:如果有人试图从 Slick 2.0-M3 开始遵循此解决方案(如下),则 HList 代码不起作用——编译超过 22 列将需要数小时和千兆字节的 RAM(它呈指数增长)groups.google.com/forum/#!topic/scalaquery/xNtPT6sexXI
-
只是为了确定,实现是正确的(据我们所知)。然而,它目前似乎会在 Scala 编译器中触发指数编译时间,这对 25 及以上的大小会非常不利。我们会研究解决这个问题。