1

我一直在玩弄幻影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]

我正在使用 Scala2.11.6和 Phantom 1.10.1,非常感谢所有帮助!

4

2 回答 2

3

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

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

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

trait KeyspaceDefinition {
  implicit val keySpace = KeySpace("sample_keyspace")
}

trait Connector extends SimpleConnector with KeyspaceDefinition
于 2015-09-10T13:16:08.967 回答
1

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

Phantom 将在编译时防止大多数坏事。值得阅读这个博客系列来了解 Cassandra 中的工作原理。

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

def getById(id: UUID): Future[Option[Student]] = {
  select.where(_.id eqs id).one()
}
于 2015-08-12T08:27:41.423 回答