Connecting cassandra cluster through scala

前端 未结 4 1636
深忆病人
深忆病人 2021-02-11 10:40

I am new in both scala and cassandra . I know the connectivity of cassandra with java using hector . But I don\'t know how to connect cassandra through scala. I want a simple ex

4条回答
  •  再見小時候
    2021-02-11 11:20

    Datastax Driver 3 Scala Integration

    I have found some articles (example) and Maga library showing how you could integrate Java Driver better with Scala and it did not look hard.

    The result is my own library that you can find on GitHub: https://github.com/atais/scassandra

    It allows for seamless integration in Scala for both CQL queries and manipulating the ListenableFuture without mapping it into scala.Future.

    implicit protected val session: com.datastax.driver.core.Session
    implicit protected val executor: java.util.concurrent.Executor
    
    val selectCQL: ListenableFuture[PreparedStatement] = cql"SELECT * FROM $table WHERE key = ?"
    val result: ListenableFuture[ResultSet] = execute(selectCQL, "my-key")
    
    result.map(rs => rs.one())
          .map(...)
    

    Enjoy :)

提交回复
热议问题