7

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?

Community
  • 1
  • 1
Meredith
  • 3,928
  • 4
  • 33
  • 58
  • I redesigned my schema in the end, in case anybody was wondering. – Meredith Sep 08 '13 at 20:22
  • 1
    I noticed [slick macros](https://github.com/ebiznext/slick-macros) the other day. It claims +22 columns for DBs as well as some other interesting stuff. Perhaps it is of some use to you. – David Weber Sep 24 '13 at 19:09

1 Answers1

2

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

Community
  • 1
  • 1
Andrew Jones
  • 1,382
  • 10
  • 26
  • How do you use that HList version? I'm using the latest Slick (2.0.0-M2) and still getting the error. – sventechie Oct 28 '13 at 01:23
  • 1
    I haven't played around with the new version, yet. User cvogt spoke about the feature at one of his talks on using Slick. I recommend getting in touch with him to ask about using HLists. – Andrew Jones Oct 28 '13 at 14:34
  • HList compiles very slow if I have 23 fields – jilen Jan 20 '14 at 07:11