I'm new to Slick. I'm creating a test suite for a Java application
with Scala, ScalaTest and Slick. I'm using slick to prepare data before
the test and to do assertions on the data after the test. The database
used has some tables with more than 22 columns. I use slick-codegen to generate my schema code.
For tables with more than 22 columns, slick-codegen does not generate a case class, but a HList-based custom type and a companion ‘constructor’ method. As I understand it, this is because the limitation that tuples and case classes can only have 22 fields. The way the code is generated, the fields of a Row-object can only be accessed by index.
I have a couple of questions about this:
override def hlistEnabled = false in an overridden SourceCodeGenerator. But this results in Cannot generate tuple for > 22 columns, please set hlistEnable=true or override compound.
So I don’t get the point of being able to disbale HList. May be the
catch is in the ‘or override compound’ part, but I don't understand what
that means.SourceCodeGenerator for some custom data types. But apart from this use case, the documentation of the code generator does not help me that much.I would really appreciate some help here. Thanks in advance!
class OrganizationTable(tag: Tag) extends Table[Organization](tag, "organization") {
def id = column[Long] ("id", O.PrimaryKey, O.AutoInc)
def name = column[String] ("name")
def rating = column[Int] ("rating")
def support = column[Boolean] ("support")
def parentId = column[Option[Long]] ("parent_id")
def regionId = column[Long] ("region_id")
def orgType = column[String] ("type")
def sector = column[String] ("sector")
def regType = column[String] ("reg_type")
def regName = column[String] ("reg_id")
def status = column[String] ("status")
def created = column[LocalDateTime]("created")
def version = column[Int]("version")
def * = (
id, regionId, name, rating, support, parentId, orgType, sector, (regType, regName), status, created, version).shaped <> (
{ case (id, regionId, name, rating, support, parentId, orgType, sector, reg, status, created, version) =>
Organization(regionId, name, parentId, orgType, sector, Registration.tupled.apply(reg),
rating, support, status, created, version, id)
},
{ o: Organization =>
Some(o.id, o.regionId, o.name, o.rating, o.support, o.parentId, o.orgType, o.sector,
Registration.unapply(o.reg).get, o.status, o.created, o.version)
})
}