问题描述
我正在尝试在 https://github.com/websudos/phantom/blob/develop/phantom-example/src/main/scala/com/websudos/phantom/example/basics/SimpleRecipes.斯卡拉,因此我创建了一个食谱并尝试使用 insertNewRecord(myRecipe)
插入它,并得到以下异常: .... InvalidQueryException:未配置的列家族my_custom_table
.我使用cqlsh进行了检查,并创建了键空间,但没有创建表.
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.
推荐答案
您需要使用架构自动生成功能创建表.只需执行:
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)
这篇关于如何使用phantom for Scala在Cassandra中创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!