How do you create a table in Cassandra using phantom for Scala?

允我心安 提交于 2021-01-28 18:11:12

问题


I am trying to run the example on https://github.com/websudos/phantom/blob/develop/phantom-example/src/main/scala/com/websudos/phantom/example/basics/SimpleRecipes.scala ,So I created a Recipe and tried to insert it using insertNewRecord(myRecipe) and got the following exception: ....InvalidQueryException: unconfigured columnfamily my_custom_table. I checked using cqlsh and the keyspace was created but the table was not.

So my question is, how do I create the table using phantom? This is never mentioned in any of the example code and I also could not figure it out by going over the phantom source code.


回答1:


You need to create the table using schema autogeneration. Simply execute:

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import com.websudos.phantom.dsl._


// To execute this, you need an implicit keySpace and a session.
Await.ready(SimpleRecipes.create.ifNotExists().future(), 3.seconds)


来源:https://stackoverflow.com/questions/31124834/how-do-you-create-a-table-in-cassandra-using-phantom-for-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!