【问题标题】:Where in select using Phantom doesn't resolve在哪里选择使用 Phantom 无法解决
【发布时间】:2015-11-03 10:13:37
【问题描述】:

我一直在玩弄幻影wiki中提供的smiple代码,我试过了;

import com.websudos.phantom.dsl._

case class Student(id: UUID, name: String)

class Students extends CassandraTable[Students, Student] {
  object id extends UUIDColumn(this) with PartitionKey[UUID]
  object name extends StringColumn(this)

  def fromRow(row: Row): Student = {
    Student(id(row), name(row))
  }
}

object Students extends Students with Connector {

  def getByName(name: String): Future[Option[Student]] = {
    select.where(_.name eqs name).one()
  }
}

但我的 IDE 一直显示 Cannot resolve symbol where 而编译器显示 value where is not a member of com.websudos.phantom.builder.query.RootSelectBlock[Students,Student]

我正在使用 Scala 2.11.6 和 Phantom 1.10.1,非常感谢所有帮助!

【问题讨论】:

    标签: scala cassandra phantom-dsl


    【解决方案1】:

    我遇到了这个问题,并使用上面@flavian 的建议解决了这个问题。

    确保您的 Connector 定义了隐式键空间。

    这是直接从示例项目中提取出来的。

    trait KeyspaceDefinition {
      implicit val keySpace = KeySpace("sample_keyspace")
    }
    
    trait Connector extends SimpleConnector with KeyspaceDefinition
    

    【讨论】:

      【解决方案2】:

      您错过了一个基本的 Cassandra 问题,您无法通过 name 查询,因为它不是索引列。根据您刚刚定义的表,您尝试执行的查询无效,Cassandra 会在运行时告诉您。

      Phantom 将在编译时防止大多数坏事。值得阅读 this blog series 以了解 Cassandra 中的工作原理。

      为了正确看待问题,唯一对您的 Students 表有效的 where 查询是:

      def getById(id: UUID): Future[Option[Student]] = {
        select.where(_.id eqs id).one()
      }
      

      【讨论】:

      • 即使将其更改为id,它仍然会抛出关于where 不是select 成员的编译错误
      • @Liam 那么你的范围内没有implicit session 或implicit keySpace。您需要两者来编译幻像查询。你从哪里复制你的例子?
      • @LiamHaworth 如果您阅读该行顶部的 cmets,它会告诉您将产生编译器错误。我认为这不够明显,我会尝试重新措辞。
      • Future[Student]可以返回吗?如果它没有发现它只是一个失败?
      • 嗨 @coolbreeze,它很容易实现,但目前不在默认 API 中,我添加了一个新方法的票证,该方法为喜欢不同 API 风格的人执行此操作。
      猜你喜欢
      • 2015-10-28
      • 2013-08-05
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 2011-01-19
      相关资源
      最近更新 更多