我该如何处理>使用嵌套元组或HList的Slick的22列表? [英] How can I handle a > 22 column table with Slick using nested tuples or HLists?
问题描述
我是Scala(使用2.10)和Slick(使用2.0-M2)的新手.我看到在Slick中解决表的22列限制的一种方法是使用嵌套元组.尽管找到了在GitHub上的部分代码,我还是不知道该怎么做.
I'm new to Scala (using 2.10) and Slick (using 2.0-M2). I see that one of the ways to get around the 22 column limit for tables in Slick is to use nested tuples. I can't figure out how to do that, despite finding this partial code on GitHub.
当前的dev分支Scala(2.11-M5)支持包含22个以上元素的case类,但不支持Arity> 22的元组.Scala2.11预发行版尚未分发Slick.如何定义33列表(并使其与所有Slick的语法糖一起使用)?
Current dev branch Scala (2.11-M5) supports case classes with more than 22 elements, but not tuples with arity > 22. And Slick is not yet distributed for Scala 2.11 pre-releases. How can I define a 33 column table (and have it work with all Slick's syntactic sugar)?
N.B.,我正在尝试支持现有架构,并且无法更改表规范化.
N.B., I'm trying to support an existing schema and can't change the table normalization.
推荐答案
在这里,我写了一篇帖子给出解决方案.这是链接: https ://lihaimei.wordpress.com/2016/03/30/slick-1-fix-more-than-22-columns-case/
Here I write a post to give out the solution. Here is the link: https://lihaimei.wordpress.com/2016/03/30/slick-1-fix-more-than-22-columns-case/
我绘制一些图形并使用不同的颜色来帮助您快速理解.
I draw some graphs and use different colors to help you understand fast.
总而言之,我使用了额外的case类将某些列打包为一个,这不会影响实际的物理列.然后,当我们使用投影来映射到自定义类型时,我们会涉及到元组返回.这是一个hack解决方案,但是很容易解决Scala编程语言的限制,即元组的大小应小于22.
To summarize, I use additional case Class to package some columns to one, which will not influence real physical columns. And then when we use projection to map to a custom type, we involve tuple back. This is a hack solution, but it is easily to fix Scala programming language's limit where the size of tuples should be less than 22.
这篇关于我该如何处理>使用嵌套元组或HList的Slick的22列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!