如何使用 Scala 幻像在 Cassandra 中创建 table?

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

我正在尝试 运行 https://github.com/websudos/phantom/blob/develop/phantom-example/src/main/scala/com/websudos/phantom/example/basics/SimpleRecipes.scala 上的示例 ,所以我创建了一个 Recipe 并尝试使用 insertNewRecord(myRecipe) 插入它并得到以下异常:....InvalidQueryException: unconfigured columnfamily my_custom_table。 我使用 cqlsh 检查并创建了密钥空间,但 table 不是。

所以我的问题是,如何使用 phantom 创建 table? 这在任何示例代码中都没有提到,我也无法通过查看幻影源代码来弄清楚。

您需要使用模式自动生成来创建 table。只需执行:

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)