java - 使用最新版本的 phantom(2.42.0) 和 scala(2.12.0-RC2) 查询数据库时未找到参数 ev:Nothing 的隐式
问题描述
我正在升级到最新版本的 phantom-dsl 2.42.0 和 scala 2.12,根据迁移指南,我现在不需要生成 fromRow() 方法,但是在查询数据库时我没有找到隐式参数(编译时间)。
我尝试编写 fromRow 方法,但仍然没有用
我的案例课程是-
case class Ball(matchId: Int,
inningsid: Int,
ballNbr: Int,
timeScore: Long,
batStrikerDots: Option[Int],
batStrikerFours: Option[Int],
commFormats: Map[String, CommentaryFormats],
.......
......)
class Ball extends Table[BallData, Ball] with CassandraSession with CommentaryPrimitive {
object matchId extends IntColumn with PartitionKey {
override lazy val name = col_name
}
object inningsId extends IntColumn with PrimaryKey with ClusteringOrder with Descending {
override lazy val name = col_name
}
object ballNbr extends IntColumn with PrimaryKey with ClusteringOrder with Descending {
override lazy val name = col_name
}
object timeScore extends DateTimeColumn with PrimaryKey with ClusteringOrder with Descending {
override lazy val name = col_name
}
object commentaryFormat extends MapColumn[String, CommentaryFormats] {
override lazy val name = "comm_format"
}
............
............
}
col_name 是各自的列名。
其中 comm_format 是 UDT,所以我定义了 CommentaryPrimitive,它注册了一个关于如何将 cassandra 数据反序列化为 scala 案例类的编解码器,而 CassandaraSession 提供了隐式密钥空间和会话。
这是我注册编解码器的原始代码 -
override def cassandraType: String = {
val format_types = CassandraConnector.getSession.getCluster.getMetadata.getKeyspace("matches_data").getUserType("format_types")
val formatCodecCodec = new CommentaryCodec(TypeCodec.userType(format_types), classOf[CommentaryFormats])
CassandraConnector.registerCodec(formatCodecCodec)
format_types.toString()
}
override def asCql(value: PrimitiveType): String = ???
override def dataType: String = ???
override def serialize(obj: PrimitiveType, protocol: ProtocolVersion): ByteBuffer = ???
override def deserialize(source: ByteBuffer, protocol: ProtocolVersion): PrimitiveType = ???
但是在查询时我无法解决这个问题-
select.where(_.matchId eqs matchId)(...).one()(...) --> 检索 Ball 对象
... ->未找到隐式
使用新版本的 phantom-dsl 它应该会自动解析 Ball 数据,但它会抛出错误,没有找到隐式。
解决方案
推荐阅读
- sql - 带有 TimescaleDB 的 PostgreSQL 在索引创建期间仅使用单个核心
- windows - ASLR 在什么逻辑上更改文件汇编代码上的内存地址?
- sql - 我正在用两个 id 创建一个唯一的 id。连接时为空值编写sql安全网的最佳方法是什么?
- javascript - 如何在 Javascript/Typescript 中创建基于类的枚举
- javascript - 当用户从textarea中的指定单词中删除字母时,如何重新隐藏按钮?
- macos - 在 Mac 上使用 Putty 尝试 mkdir /root/.local/share 时的只读文件系统
- pytorch - 关于使用 PyTorch 编写 cnn 的问题
- javascript - try 块中的 return 语句是否等待 finally 块中的 await 语句?
- css - 对于 Angular 9 mat-tables,有没有办法在一个地方为一行设置 CSS 颜色?
- reactjs - 为什么在 then() 内部存在数据,而外部不存在 - Axios 返回未定义