Scala 22param limit trying to find a workaround and still use for comprehensions instead of plain SQL in Slick

database, scala, slick, sql, tuples

Solution

I stumbled on this question after answering a similar question a couple days ago. Here's a link to the question. slick error : type TupleXX is not a member of package scala (XX > 22)

To answer the question here, you are able to use nested tuples to solve the 22 column limit. When solving the problem myself, the following post was extremely helpful. https://groups.google.com/forum/#!msg/scalaquery/qjNW8P7VQJ8/ntqCkz0S4WIJ

Another option is to use the soon-to-be-released version of Slick which uses HLists to remove the column count limitation. This version of Slick can be pulled from the Slick master branch on Github. Kudos to cvogt for pointing out this option. https://github.com/slick/slick/blob/master/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala#L249

Problem

I'm working with 23 fields here, at last count. I've generally thrown my hands up with trying to count them after reducing from a 31-fielded table by using a foreign-key. All the good links Fundamental explanation of how to read and understand Slick's schema code provided by one very good Faiz. On 22+ parameters... Stefan Zeigar has been immensely helpful in the example code he's written in this discussion and also more directly linked to here on Github The good Stefan Zeigar has also posted here on plain SQL queries What this post is about I think the above is enough to get me on my way to a working refactoring of my app so that CRUD is feasible. I'll update this question or ask new questions if something comes up and stagnates me. The thing is... I miss using for comprehensions for querying. I'm talking about Slick's Query Templates The problem I run into when I use a for comprehensions is that the table... will probably have ``` object Monsters extends Table[Int]("monster_table"){ // lots of column definitions def * = id /* for a Table[Int] despite having 21 other columns I'm not describing in this projection/ColumnBase/??? */ } ``` and the `*` projection won't describe everything I want to return in a query. The usual simple for comprehension Slick query template will look something like this: ``` def someQueryTemplate = for { m <- Monsters } yield m ``` and `m` will be an Int instead of the entire object I want because I declared the table to be a `Table[Int]` because I can't construct a mapped projection of 22 params because of all the code that needs to be generated for compiler support of class generation for each tuple and arbitrariness So... in a nutshell: Is there any way to use Query Templates in Slick with 22+ columns?

Original source

Related problems