簡體   English   中英

在Scala中使用Phantom在Cassandra中創建表

[英]Creating a table in Cassandra using Phantom in Scala

我在這里關注該教程: http : //blog.websudos.com/2015/04/04/a-series-on-phantom-part-1-getting-started-with-phantom/

Cassandra版本:2.1.8

Phatom版本1.10.1

Scala版本: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)
  }
}

當我從sbt 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並創建了名稱空間, 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._"

Users.store返回什么? 如果返回Future [ResultSet] ,則等待將來完成。 嘗試等待並檢查。

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

val resultSetFuture = Users.store(user)
Await.result(resultSetFuture, Duration.Inf) 

首先,您需要創建表:(在第一次運行后發表評論,否則您將收到“表已存在異常:P)

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

然后刪除.consistencyLevel_=(ConsistencyLevel.ALL)因為幻影庫似乎在cassandra中發生了很大的變化,后者說ConsistencyLevel現在是按會話而不是按請求定義的。

現在應該可以使用,但是我會說這個庫看起來不太有希望。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM