1

我在这里学习教程:http: //blog.websudos.com/2015/04/04/a-series-on-phantom-part-1-getting-started-with-phantom/

卡桑德拉版本:2.1.8

Phatom版本 1.10.1

斯卡拉版本:2.11.2

sbt 版本:0.13.8

除了文章中给出的代码之外,我还有以下内容:

object App {
  def main(args: Array[String]) {
    val user = new User(UUID.fromString("00000000-0000-0000-0000-000000000000"), "test@test.com", "Dan", DateTime.now)
   val resultSetFuture = Users.store(user)
   Await.result(resultSetFuture, Duration.Inf)
  }
}

当我run的程序来自sbt我得到以下错误(这里是堆栈跟踪的头部):

[error] (run-main-0) com.datastax.driver.core.exceptions.SyntaxError: line 1:157 no viable alternative at input 'CONSISTENCY' (..., 'Dan', 1437914728864) USING [CONSISTENCY]...)
com.datastax.driver.core.exceptions.SyntaxError: line 1:157 no viable alternative at input 'CONSISTENCY' (..., 'Dan', 1437914728864) USING [CONSISTENCY]...)

我已经检查csqlsh并创建了命名空间,但没有创建表。

非常感谢任何帮助。

build.sbt是有用的情况:

name := "Something"

organization := "danmisun.github.com"

version := "0.1.0-SNAPSHOT"

scalaVersion := "2.11.2"

crossScalaVersions := Seq("2.10.4", "2.11.2")

val PhantomVersion = "1.10.1"

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "2.2.1" % "test",
  "org.scalacheck" %% "scalacheck" % "1.11.5" % "test",
  "com.websudos" % "phantom_2.11" % PhantomVersion,
  "com.websudos" % "phantom-dsl_2.11" % PhantomVersion,
  "com.websudos" % "phantom-testkit_2.11" % PhantomVersion % "test,   provided"
)

resolvers ++= Seq(
  "Typesafe repository snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
  "Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/",
  "Sonatype repo"                    at "https://oss.sonatype.org/content/groups/scala-tools/",
  "Sonatype releases"                at "https://oss.sonatype.org/content/repositories/releases",
  "Sonatype snapshots"               at "https://oss.sonatype.org/content/repositories/snapshots",
  "Sonatype staging"                 at "http://oss.sonatype.org/content/repositories/staging",
  "Java.net Maven2 Repository"       at "http://download.java.net/maven/2/",
  "Twitter Repository"               at "http://maven.twttr.com",
  Resolver.bintrayRepo("websudos", "oss-releases")
)

initialCommands := "import something._"
4

2 回答 2

1

Users.store 返回什么?如果它返回Future[ResultSet],则等待未来完成。尝试等待并检查。

import scala.concurrent.{ Await, Future }
import scala.concurrent.duration.Duration

val resultSetFuture = Users.store(user)
Await.result(resultSetFuture, Duration.Inf) 
于 2015-07-26T11:50:54.327 回答
1

首先你需要创建表:(第一次运行后评论,否则你会收到“表已经存在异常:P)

Await.result(Users.create.future(), 5000 millis)

然后删除.consistencyLevel_=(ConsistencyLevel.ALL),因为幻像库似乎非常落后于 cassandra 中的更改,这表明 ConsistencyLevel 现在是每个会话而不是每个请求定义的。

现在应该可以了,但是我会说这个库看起来不太有希望。

于 2015-07-27T20:25:06.487 回答