问题描述
我已经创建了一个自定义生成器,以将数据库映射到我的应用程序,但是遇到了问题.我已经对其进行了自定义,以生成自动递增列作为可选列,所以我做到了:
I've created a custom generator to map my database into my app and I'm having an issue. I've customized it to generate the auto increment columns as optional, so I've made this:
val codegen = new scala.slick.model.codegen.SourceCodeGenerator(model) {
override def Table = new Table(_){
override def autoIncLastAsOption = true
}
}
对于具有多于22列的表,它使用HList实现而不是Scala元组.它正在生成此:
For the tables that has more than 22 columns, it uses HList implementation and not the Scala Tuple. It is generating this:
implicit def GetResultVoicemailRow(implicit e0: GR[String], e1: GR[Short], e2: GR[java.sql.Timestamp], e3: GR[Option[Int]]): GR[VoicemailRow] = GR{
prs => import prs._
val positional = <<?[Int] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[Short] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[String] :: <<[java.sql.Timestamp] :: HNil
import positional._
r(1) :: r(2) :: r(3) :: r(4) :: r(5) :: r(6) :: r(7) :: r(8) :: r(9) :: r(10) :: r(11) :: r(12) :: r(13) :: r(14) :: r(15) :: r(16) :: r(17) :: r(18) :: r(19) :: r(20) :: r(21) :: r(22) :: r(23) :: r(24) :: r(0) :: HNil // putting AutoInc last
}
这导致编译错误. 未找到:值r".我该怎么做才能解决这个问题?谢谢.
This is causing a compilation error. "not found: value r". What can I do to solve this?Thanks.
推荐答案
看起来像Slick 2.0.1-RC1中的错误.
Looks like a bug in Slick 2.0.1-RC1.
作为解决方法,请使用以下修复程序自定义代码生成器.
As a workaround customize the code generator with the following fix.
http://slick.typesafe.com/doc/2.0.1-RC1/code-generation.html#customization
class MyCodeGenerator(model: Model) extends SourceCodeGenerator(model: Model){
protected def mytuple(i: Int) = termName(s"_${i+1}")
override def Table = new Table(_){
override def autoIncLastAsOption = true
override def PlainSqlMapper = new PlainSqlMapper{
override def code = {
val positional = compound(columnsPositional.map(c => (if(c.fakeNullable || c.model.nullable)s"<<?[${c.rawType}]"else s"<<[${c.rawType}]")))
val dependencies = columns.map(_.exposedType).distinct.zipWithIndex.map{ case (t,i) => s"""e$i: GR[$t]"""}.mkString(", ")
val rearranged = compound(desiredColumnOrder.map(i => if(hlistEnabled) s"r($i)" else mytuple(i)))
def result(args: String) = if(mappingEnabled) s"$factory($args)" else args
val body =
if(autoIncLastAsOption && columns.size > 1){
s"""
val r = $positional
import r._
${result(rearranged)} // putting AutoInc last
""".trim
} else
result(positional)
s"""
implicit def ${name}(implicit $dependencies): GR[${TableClass.elementType}] = GR{
prs => import prs._
${indent(body)}
}
""".trim
}
}
}
}
这篇关于表格>的Slick编译错误22列(使用HLists)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!