Phantom -dsl_2.11 implicit session error

I am trying to connect to cassandra database (with scala 2.11.2) using phantom scala driver

I followed this article on my blog: http://blog.websudos.com/2014/08/a-series-on-cassandra-part-1-getting-rid-of-the-sql-mentality/

(note on github only 2 phantom -dsl jar compiled in 2.11, I don't know if there is a problem?)

I have only one dependency with phantom

<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> 

When I compile my project, I get this session error:

 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] ------------------------------------------------------------------------ 

Their github has a session example:

  implicit val session = SomeCassandraClient.session; 

But I do not understand where SomeCassandraClient is located?

Any tips?

+5
source share
2 answers

You can take a session from your connector (which is the "SomeCassandraClient that you are looking for).

Somewhere you defined your connector as:

 trait Connector extends SimpleCassandraConnector { val keySpace = "your_keyspace" // other connection params as needed } object Connector extends Connector 

then just do

 implicit val session = Connector.session 

Thus, you do not need to define your IP connection and key space several times; -)

+2
source

When you define a phantom table, a very common practice is to enter a session with a simple attribute. That is why we created connectors so that they can automatically provide a session using the mixin / inheritance method.

 import com.websudos.phantom.connectors.SimpleCassandraConnector trait MyConnector extends SimpleCassandraConnector { override val keySpace = "whatever" } 

Now that you define the class MyTable , you must define:

 object MyTable extends MyTable with MyConnector { def getById(id: String): Future[Option[..]] { } } 

You should also use the newer version of Phantom, respectively 1.5.0. Scala 2.11 support was relatively new in 1.2.7, so strange problems may occur because of this, but they are all fixed now.

You also do not need to worry about creating multiple objects. When using connectors, the Cassandra base connection is actually global, with all the corresponding locks in place. What you do is the same exercise for all your tables, even if it may not be displayed.

+2
source

Source: https://habr.com/ru/post/1209174/


All Articles