假设我有一个包含许多小列和一个大(比如 BLOB)列的表:
case class Thing(id: Int, small1: String, small2: String, small3: String, large: String)
class ThingMapping(tag: Tag) extends Table[Thing](tag, "things") {
def id = column[Int]("id", O.PrimaryKey, O.NotNull, O.AutoInc)
def small1 = column[String]("small1")
def small2 = column[String]("small2")
def small3 = column[String]("small3")
def large = column[String]("large")
def * = (id, small1, small2, small3, large) <> (Thing.tupled, Thing.unapply)
}
在某些情况下,我想查询表中除列之外的所有large
列。在其他情况下,我想包括它。我更喜欢使用案例类而不是元组。
Slick 中是否有很好的模式来执行此操作?
我考虑过的选项:
- 有两个映射——“瘦”和“胖”映射。
- 将大列拆分为单独的表,然后在需要时将其加入。