Slick 3.3.3Loading… manual

Cookbook

This section of the manual is for solutions to common questions.

Mapping more than 22 fields

Problem

You have a table with more than 22 fields, and the Scala 2 compiler has told you:

too many elements for tuple: 23, allowed: 22

Solution

Switch from using a tuple in your default projection to using an HList.

First, add the HList imports:

import slick.collection.heterogeneous.{HList, HCons, HNil}
import slick.collection.heterogeneous.syntax._
Cookbook.scala

Your case class and table definition are as unchanged, but your default projection ( the * method) changes:

case class Row(id: Int, name: String /* ... as many as you like */)

class MyTable(tag: Tag) extends Table[Row](tag, "ROW") {
  def id   = column[Int]("ID", O.PrimaryKey)
  def name = column[String]("NAME")
  /* ... as many as you like */

  def * = (id :: name /* as many as you like... */ :: HNil).mapTo[Row]
}
Cookbook.scala