无法使用phantom-dsl将模式转换为cassandra

时间:2017-01-10 12:47:24

标签: scala cassandra phantom-dsl

尝试使用phantom-dsl在本教程之后使用[ERROR] /home/.../test/BaseCassandraSpec.scala:54: error: not enough arguments for method autocreate: (keySpace: com.websudos.phantom.connectors.KeySpace) com.websudos.phantom.builder.query.CreateQuery.Default[com.neruti.db.models.ConcreteUserModel,com.neruti.User]. [ERROR] Unspecified value parameter keySpace. [ERROR] Await.result(database.userModel.autocreate().future(),10.seconds) 创建一个架构到cassandra中:

http://outworkers.com/blog/post/phantom-tips-3-understanding-phantom-connectors

我在尝试自动生成架构时遇到了这个问题

1.29.6

有什么建议吗?

目前使用版本import com.neruti.User import com.neruti.db.models._ import com.neruti.db.databases._ import com.neruti.db.services._ import com.neruti.db.Connector._ import org.scalatest._ import org.scalatest.{BeforeAndAfterAll,FlatSpec,Matchers,ShouldMatchers} import org.scalatest.concurrent.ScalaFutures import org.scalamock.scalatest.MockFactory import scala.concurrent.duration._ import scala.concurrent.{Await, Future} import scala.concurrent.ExecutionContext.Implicits.global override protected def beforeAll(): Unit = { Await.result(database.userModel.autocreate().future(),10.seconds) }

BaseCassandraSpec

class UserDatabase (val connector: KeySpaceDef){
  object userModel extends ConcreteUserModel with connector.Connector
}

object ProductionDb extends UserDatabase(connector)

trait ProductionDatabaseProvider {
  def database: UserDatabase
}

trait ProductionDatabase extends ProductionDatabaseProvider {
  override val database = ProductionDb
}

object testDB extends UserDatabase(testConnector)

trait testDatabaseProvider {
  def database: UserDatabase
}

trait testDatabase extends testDatabaseProvider{
  override val database = testDB
}

数据库

package com.neruti.db

import com.neruti.db.models._

import com.websudos.phantom.database.Database
import com.websudos.phantom.connectors.ContactPoints
import com.websudos.phantom.dsl.KeySpaceDef

object Connector {



    // TODO: these key value pairs shld get from HOCON config file
      val host= Seq("127.0.0.1")
      val port = 9042
      val keySpace: String = "nrt_entities"
      //  val inet = InetAddress.getByName

      lazy val connector = ContactPoints(host,port).withClusterBuilder(
        _.withCredentials("dev", "nrtDev1989")
      ).keySpace(keySpace)

      //  embedded cassandra is not supported anymore.  Check phantom-sbt.
      //    lazy val testConnector: KeySpaceDef = ContactPoint.embedded.keySpace(keySpace)
      lazy val testConnector: KeySpaceDef = ContactPoints(host,port).noHeartbeat().keySpace(keySpace)
    }

连接器

var flag = 0;

function username() {
  usrn = document.form1.txt.value;
  if (usrn == "") {
    document.getElementById("user").innerHTML = "Please enter a username";
    flag = 1;
  } else if (usrn.length < 8) {
    document.getElementById("user").innerHTML = "minimum 8 characters required";
    flag = 1;
  }

}

function password() {
  pass = document.form1.pass.value;
  cpass = document.form1.cpass.value;
  if (pass == "") {
    document.getElementById("password").innerHTML = "Please enter a password";
    flag = 1;
  } else if (pass.length < 8) {
    document.getElementById("password").innerHTML = "minimum 8 characters required";
    flag = 1;
  } else if (cpass == "") {
    document.getElementById("cpassword").innerHTML = "Please confirm password";
    flag = 1;
  } else if (cpass != pass) {
    document.getElementById("cpassword").innerHTML = "passwords do not match";
    flag = 1;
  } else
    return;
}

function cpassword() {
  cpass = document.form1.cpass.value;
  pass = document.form1.pass.value;
  if (cpass == "") {
    document.getElementById("cpassword").innerHTML = "Please confirm password";
    flag = 1;
  } else if (cpass != pass) {
    document.getElementById("cpassword").innerHTML = "passwords do not match";
    flag = 1;
  } else
    return;
}

function email() {
  email = document.form1.em.value;
  if (email == "") {
    document.getElementById("emailid").innerHTML = "Please enter Email-ID";
    flag = 1;
  }
}

function check(form) {
  flag = 0;
  username();
  password();
  email();
  if (flag == 1) {
    return false;
  } else {
    return true;
  }
}

1 个答案:

答案 0 :(得分:0)

作为旁注,我会升级到幻像2.0.0。接下来,在代码中有许多需要改进的地方,从特征的大写开始。

您应该使用database.createdatabase.createAsync,这不再需要您重新传递隐式密钥空间或会话。请记住,此API是phantom-dsl的版本2.1.1,可在Maven Central上找到。

package com.neruti.db

import com.neruti.db.models._

import com.outworkers.phantom.connectors.ContactPoints
import com.outworkers.phantom.dsl._

object Connector {



    // TODO: these key value pairs shld get from HOCON config file
      val host= Seq("127.0.0.1")
      val port = 9042
      val keySpace: String = "nrt_entities"
      //  val inet = InetAddress.getByName

      lazy val connector = ContactPoints(host,port).withClusterBuilder(
        _.withCredentials("dev", "nrtDev1989")
      ).keySpace(keySpace)

      lazy val testConnector: KeySpaceDef = ContactPoints(host, port).noHeartbeat().keySpace(keySpace)
    }


class MyDb(override val connector: CassandraConnection) extends Database(connector) {
  ... tables
}

object TestMyDb extends MyDb(Connector.testConnector)

import com.outworkers.phantom.dsl.context
// Now this will only require an execution context, nothing more
TestMyDb.create()