我正在尝试将超过22列的数据库行映射到案例类树.我宁愿不使用HList,因为我不想使用该API,还有一些我在某处读过的指数编译时间反馈......
我已经读过Stefan Zeiger回答的这个帖子:如何使用嵌套元组或HLists处理带有Slick的> 22列表?
我已经看过这个测试,它展示了如何定义自定义映射函数,我想这样做:
def * = (
id,
(p1i1, p1i2, p1i3, p1i4, p1i5, p1i6),
(p2i1, p2i2, p2i3, p2i4, p2i5, p2i6),
(p3i1, p3i2, p3i3, p3i4, p3i5, p3i6),
(p4i1, p4i2, p4i3, p4i4, p4i5, p4i6)
).shaped <> ({ case (id, p1, p2, p3, p4) =>
// We could do this without .shaped but then we'd have to write a type annotation for the parameters
Whole(id, Part.tupled.apply(p1), Part.tupled.apply(p2), Part.tupled.apply(p3), Part.tupled.apply(p4))
}, { w: Whole =>
def f(p: Part) = Part.unapply(p).get …Run Code Online (Sandbox Code Playgroud) 我有嵌套的类/对象,并希望使用SLICK在数据库中存储(和检索)它们.据我所知,使用SLICK映射投影将是关键.此外,我使用伴侣对象在嵌套对象和平面结构之间进行映射(存储在DB表中).我想做这样的事情(简化示例):
case class Foo(id: Int, myBar: Bar)
case class Bar(myInt: Int, myString: String)
object Foo {
def apply(id: Int, myInt: Int, myString: String): Foo = Foo(id, Bar(myInt, myString))
override def unapply(f: Foo) = (f.id, f.myBar.myInt, f.myBar.myString)
}
object TTable extends Table[Foo]("FOO") {
def id = column[Int]("id", O.PrimaryKey)
def myInt = column[Int]("myInt", O NotNull)
def myString = column[String]("myString", O NotNull)
def * = id ~ myInt ~ myString <> (Foo.apply _, Foo.unapply _)
def query(db: Database, id: Int): Option[Foo] = db …Run Code Online (Sandbox Code Playgroud) 我是Slick的新手,正在使用Slick 3.1.1。我的桌子看起来像
import java.sql.{Blob, Timestamp}
import slick.collection.heterogeneous.HNil
import slick.driver.MySQLDriver.api._
case class AnomalyC(id: Int, serviceName: String, serviceId: String, timeUpdated: Timestamp, timestamp: Timestamp, anomalyCategoryId: Int,
userGroup:Int, riskValue: Float, activityTypeId: Int, destinationHost: String, userName: String, tenantId: Int, information:Blob, timeCreated: Timestamp, userId: Int, anomalyType:Int, anomalyValue:String, measure:Int,
userAction:Int, uniqueIdentifier:Int, similarCount:Int, trainingValue:String, state: Int, riskLevel:Int, userRiskLevel:Int,
userRiskScore: Float, response:Int)
class Anomaly(tag:Tag) extends Table[AnomalyC](tag, "Anomaly") {
def id = column[Int]("id")
def serviceName = column[String]("ServiceName")
def serviceId = column[Int]("ServiceId")
def timeUpdated = column[Timestamp]("TimeUpdated")
def timestamp = …Run Code Online (Sandbox Code Playgroud) 在使用Slick调用程序时,我们如何克服22限制?
我们目前有:
val q3 = sql"""call getStatements(${accountNumber})""".as[Transaction]
Run Code Online (Sandbox Code Playgroud)
问题是我们必须返回超过22列,而Transaction case类不能超过22列,因为当我们执行JSONFormat时,我们得到一个错误:
[error] E:\IdeaProjects\admin\Transaction.scala:59: No unapply or unapplySeq function found
[error] implicit val jsonFormat = Json.format[Transaction]
Run Code Online (Sandbox Code Playgroud)
有什么建议?