我该如何处理 >使用嵌套元组或 HLists 使用 Slick 的 22 列表? [英] How can I handle a > 22 column table with Slick using nested tuples or HLists?

查看:21
本文介绍了我该如何处理 >使用嵌套元组或 HLists 使用 Slick 的 22 列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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.

当前的开发分支 Scala (2.11-M5) 支持具有超过 22 个元素的案例类,但不支持 arity > 22 的元组.并且 Slick 尚未针对 Scala 2.11 预发行版分发.如何定义一个 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., 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 Class将一些列打包成一个,这不会影响真正的物理列.然后当我们使用投影映射到自定义类型时,我们涉及到元组返回.这是一个 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.

这篇关于我该如何处理 >使用嵌套元组或 HLists 使用 Slick 的 22 列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆