如何使用phantom for Scala在Cassandra中创建表? [英] How do you create a table in Cassandra using phantom for Scala?

查看:55
本文介绍了如何使用phantom for Scala在Cassandra中创建表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在

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中创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆