- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在将具有 > 22 列的表专门映射到 case class
时遇到问题,假设您有以下代码
import slick.driver.PostgresDriver
import scala.slick.collection.heterogenous._
import syntax._
import shapeless.Generic
case class TwentyThreeCaseClass(
val id:Option[Long],
val one:String,
val two:String,
val three:String,
val four:String,
val five:String,
val six:String,
val seven:String,
val eight:String,
val nine:String,
val ten:String,
val eleven:String,
val twelve:String,
val thirteen:String,
val fourteen:String,
val fifteen:String,
val sixteen:String,
val seventeen:String,
val eighteen:String,
val nineteen:String,
val twenty:String,
val twentyOne:String,
val twentyTwo:String,
val twentyThree:String,
val twentyFour:String
)
class TwentyThreeTable(tag:Tag) extends Table[TwentyThreeCaseClass](tag,"twenty_three_table") {
def id = column[Long]("id",O.PrimaryKey,O.AutoInc)
def one = column[String]("one")
def two = column[String]("two")
def three = column[String]("three")
def four = column[String]("four")
def five = column[String]("five")
def six = column[String]("six")
def seven = column[String]("seven")
def eight = column[String]("eight")
def nine = column[String]("nine")
def ten = column[String]("ten")
def eleven = column[String]("eleven")
def twelve = column[String]("twelve")
def thirteen = column[String]("thirteen")
def fourteen = column[String]("fourteen")
def fifteen = column[String]("fifteen")
def sixteen = column[String]("sixteen")
def seventeen = column[String]("seventeen")
def eighteen = column[String]("eighteen")
def nineteen = column[String]("nineteen")
def twenty = column[String]("twenty")
def twentyOne = column[String]("twentyOne")
def twentyTwo = column[String]("twentyTwo")
def twentyThree = column[String]("twentyThree")
def twentyFour = column[String]("twentyFour")
private def iso[L <: HList, M <: HList](l: L)
(implicit iso: Generic.Aux[TwentyThreeCaseClass, M], eq: L =:= M): TwentyThreeCaseClass = iso.from(l)
def * =
id.? ::
one ::
two ::
three ::
four ::
five ::
six ::
seven ::
eight ::
nine ::
ten ::
elven ::
twelve ::
thirteen ::
fourteen ::
fifteen ::
sixteen ::
seventeen ::
eighteen ::
nineteen ::
twenty ::
twentyOne ::
twentyTwo ::
twentyThree ::
twentyFour ::
HNil
// Do stuff here to map to a case class
}
TwentyThreeCaseClass
中? .给出了如何制作光滑的示例代码
Table
映射到 HList,但没有给出关于如何通过
HList
将表映射到案例类 > 22 个参数的代码(您不能使用元组,因为 Scala 中的元数限制仍然适用于元组,您不能创建包含超过 22 个元素的元组)
iso
在那里,因为我们使用这个通用的 iso 代码从
HList
映射到
case class
在 slick 之外的无形状代码中具有相同的形状,因此从理论上讲,您应该能够使用 iso 从
HList
构造案例类,我只是不知道如何在光滑形状的上下文中使用 iso
最佳答案
想通了,虽然它很丑,因为它不是通用的。
def * =
(id.? ::
one ::
two ::
three ::
four ::
five ::
six ::
seven ::
eight ::
nine ::
ten ::
elven ::
twelve ::
thirteen ::
fourteen ::
fifteen ::
sixteen ::
seventeen ::
eighteen ::
nineteen ::
twenty ::
twentyOne ::
twentyTwo ::
twentyThree ::
twentyFour ::
HNil).shaped <>
({case x => TwentyThreeCaseClass(
x(0),
x(1),
x(2),
x(3),
x(4),
x(5),
x(6),
x(7),
x(8),
x(9),
x(10),
x(11),
x(12),
x(13),
x(14),
x(15),
x(16),
x(17),
x(18),
x(19),
x(20),
x(21),
x(22),
x(23),
x(24)
)}, ({x:TwentyThreeCaseClass =>
Option((
x.id ::
x.one ::
x.two ::
x.three ::
x.four ::
x.five ::
x.six ::
x.seven ::
x.eight ::
x.nine ::
x.ten ::
x.eleven ::
x.twelve ::
x.thirteen ::
x.fourteen ::
x.fifteen ::
x.sixteen ::
x.seventeen ::
x.eighteen ::
x.nineteen ::
x.twenty ::
x.twentyOne ::
x.twentyTwo ::
x.twentyThree ::
x.twentyFour ::
HNil
))
}))
HList
实现(与 shapeless 的语法完全相同!)HList
似乎没有任何通用方法来处理诸如映射到 case class
之类的事情。 (并从案例类到 Slick `HLIst)Hlist
到无形HList
会很方便,或者 Slick 的通用能力 Hlist
.前者可能是更好的选择,因为 shapeless 已经比 Slick 做通用的东西好得多,而且它可能超出了 Slicks 的范围 def gen = Generic[TwentyThreeCaseClass]
...
.shaped <>
({case x => gen.from(x)}, {TwentyThreeCaseClass => Option(gen.to(x))})
关于scala - Slick 2.10-RC1,Scala 2.11.x,使用 case 类绕过 22 arity 限制(异构),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24978042/
我经常在 ATS 中看到使用 case、case+ 或 case- 形成的 case 表达式。有什么区别? 最佳答案 如果表达式不详尽,使用 case 会发出警告,case+ 会产生错误,而 case
我有一个导入时全部大写的表,我想将其转换为正确的大小写。你们用什么脚本来完成这个? 最佳答案 这个函数: “正确大小写”由空格分隔的所有“大写”单词 保留“小写单词” 即使对于非英语字母也能正常工作
#include int main() { switch(2) { case 1: if(1)
我已经四处寻找了一段时间,如果我使用的术语不当,请原谅我... 代码的目标是在输入为 0 时更新 Aout1 和 Aout0,输出对应于 7 段显示,但出现以下错误: “错误 (10170):Four
我正在尝试按照 PostgreSQL 手册中的说明进行操作。 PostgreSQL: Documentation: 9.1: Control Structures 我的 PostgreSQL 服务器是
我有一个状态机,其中有几个非常相似的状态。我可以为每个状态编写它,如下例所示: module CHECK_FSM ( GO, DONE, CLK, RESETN ); input GO;
如何使用或创建案例? 就像是: string str; case (str) "abc" || "dfg": begin //some code end "yfg":
这个问题已经有答案了: Are double and single quotes interchangeable in JavaScript? (23 个回答) 已关闭 9 年前。 我正在学习Java
汽车 Make | Model | Year | Color Honda | Accord | 12 | Red Lexus | IS | 14 |
如何使用当前 case 语句的值跳转到 switch-case 条件下的另一个 case 语句? 是否可以使用 switch case 来实现这种事情,或者是否有其他实现方式? 有可能实现吗?如果没有
我理解下面的代码。 var day = 2; switch (day) { case 1: document.write("Monday"); break;
这是有效的。 object FilesToDFDS { case class Student(id: Int, name: String, dept:String) def main(
我对 VHDL 还是个新手。我需要在 CASE 语句中为多个信号赋值,如下所示: CASE input24 IS WHEN "00" THEN output0
我有这个 case 语句,它给出了一个错误“变量 constant1 未使用”。它似乎忽略了变量并返回了第一行,因此变量显然没有范围。如果我用数字 1 替换常量,那么它就可以工作。在 Elixir 中
在 MySQL 中,是否可以在 SELECT 子句中有两个 CASE 语句,其中第二个 CASE 语句依赖于第一个 CASE 语句? 例如,考虑以下查询: SELECT CASE WHEN `user
我正在尝试一个挑战,我需要获得一个随机数,并在没有重复的情况下打印数字内的数字总和:例如,123 将打印 6 ( 1 + 2 + 3 ),而 32111 将做同样的事情(因为我们没有在我们的总和中添加
当有人试图更新当前未存储在我的散列中的值时,我想立即返回 when 'add' 而无需重新启动整个 case声明,因为我已经知道他们想要添加并且不想再次提示他们。 有没有一种方法可以在不重新启动整个案
老 C 程序员可以在 Swift 方面得到一些帮助。 我不太了解 if-case 语法。例如: if case 20...30 = age { print ("in range.") } cas
老 C 程序员可以在 Swift 方面得到一些帮助。 我不太了解 if-case 语法。例如: if case 20...30 = age { print ("in range.") } cas
我有一个 ArrayList,其中包含以下字符串:[name, age, gender, salary] . 有没有办法可以将 ArrayList 中的值用作 case 表达式? 显而易见的答案是否定
我是一名优秀的程序员,十分优秀!