Gui*_*ume 5 scala cassandra maven phantom-dsl
我正在尝试使用幻像scala驱动程序连接到cassandra数据库(使用scala 2.11.2)
我在他们的博客上关注了这篇文章:http: //blog.websudos.com/2014/08/a-series-on-cassandra-part-1-getting-rid-of-the-sql-mentality/
(注意github上只有2.11中编译的幻像-dsl jar,我不知道是否有问题?)
我只有一个依赖幻像的依赖
<dependency>
<groupId>com.websudos</groupId>
<artifactId>phantom-dsl_2.11</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.0.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我编译我的项目时,我收到有关会话的错误:
Main.scala:32: error: could not find implicit value for parameter session: com.datastax.driver.core.Session
[ERROR] select.where(_.firstName eqs firstName).limit(5000).fetch()
[ERROR] ^
[ERROR] one error found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
在他们的github上,有一个会话示例:
implicit val session = SomeCassandraClient.session;
Run Code Online (Sandbox Code Playgroud)
但我不明白SomeCassandraClient的位置?
有什么建议?
您可以从连接器(即您正在寻找的“SomeCassandraClient”)获取会话。
您在某个地方定义了连接器,例如:
trait Connector extends SimpleCassandraConnector {
val keySpace = "your_keyspace"
// other connection params as needed
}
object Connector extends Connector
Run Code Online (Sandbox Code Playgroud)
然后就做一个
implicit val session = Connector.session
Run Code Online (Sandbox Code Playgroud)
这样你就不必多次定义你的连接 IP 和密钥空间;-)