我正在尝试添加一个通用的Slick Entity / Table帮助程序类:
trait HasSlickProfile {
val profile: JdbcProfile
}
trait SlickedDBConfig
extends HasSlickProfile {
lazy val profile: JdbcProfile = ???
}
abstract class EntityHelper[E]
extends HasSlickProfile {
import profile.api._
type T <: Table[E]
def table: TableQuery[_ <: Table[E]]
// TONS OF USEFULL ENTITY / TABLE STUFF
}
但它不能编译:
object ValueOfHelper
extends EntityHelper[ValueOf]
with SlickedDBConfig {
import profile.api._
type T = ValueOfTable
val table = ValueOfTable
}
因为发现了错误:
[error] /.../ValueOfHelper.scala:22: overriding type T in class EntityHelper with bounds <: fp.model.ValueOfHelper.profile.api.Table[fp.model.Tables.ValueOf];
[error] type T has incompatible type
[error] type T = ValueOfTable
[error] ^
[error] /.../ValueOfHelper.scala:23: overriding method table in class EntityHelper of type => fp.model.ValueOfHelper.profile.api.TableQuery[_ <: fp.model.ValueOfHelper.profile.api.Table[fp.model.Tables.ValueOf]];
[error] value table has incompatible type
[error] val table = ValueOfTable
[error] ^
自动生成的表格如下所示:
import slicked.codegen.SlickedDBConfig
object Tables extends {
} with Tables
with SlickedDBConfig
trait Tables {
val profile: slick.jdbc.JdbcProfile
import profile.api._
// Custom imports start
import slicked.SlickedRow
import slicked.SlickedTable
import slicked.SlickMappers._
// Custom imports end
import slick.model.ForeignKeyAction
import slick.jdbc.{GetResult => GR}
lazy val schema: profile.SchemaDescription = ValueOfTable.schema
case class ValueOf(of: String, in: String, timestamp: org.joda.time.DateTime, `val`: Int, info: Option[String] = None) extends SlickedRow
implicit def GetResultValueOf(implicit e0: GR[String], e1: GR[org.joda.time.DateTime], e2: GR[Int], e3: GR[Option[String]]): GR[ValueOf] = GR{
prs => import prs._
ValueOf.tupled((<<[String], <<[String], <<[org.joda.time.DateTime], <<[Int], <<?[String]))
}
class ValueOfTable(_tableTag: Tag) extends profile.api.Table[ValueOf](_tableTag, Some("forex"), "VALUE_OF") with SlickedTable {
def * = (of, in, timestamp, `val`, info) <> (ValueOf.tupled, ValueOf.unapply)
def ? = (Rep.Some(of), Rep.Some(in), Rep.Some(timestamp), Rep.Some(`val`), info).shaped.<>({r=>import r._; _1.map(_=> ValueOf.tupled((_1.get, _2.get, _3.get, _4.get, _5)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
val of: Rep[String] = column[String]("OF", O.Length(16,varying=true))
val in: Rep[String] = column[String]("IN", O.Length(16,varying=true))
val timestamp: Rep[org.joda.time.DateTime] = column[org.joda.time.DateTime]("TIMESTAMP")
val `val`: Rep[Int] = column[Int]("VAL")
val info: Rep[Option[String]] = column[Option[String]]("INFO", O.Default(None))
val index1 = index("VALUEOF_TIMESTAMP_OF_IN_pk", (timestamp, of, in), unique=true)
}
lazy val ValueOfTable = new TableQuery(tag => new ValueOfTable(tag))
}
如何将其编写为与配置文件无关?