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
I've been working on Scala wrapper of Java Driver to minimize boilerplate code. You could find it here: https://github.com/InnovaCo/binders-cassandra
Here is an example of class that works with some Cassandra DB:
class Db(session: com.datastax.driver.core.Session) {
implicit val cache = new SessionQueryCache[PlainConverter](session)
// class for binding input/output parameters
case class User(userId: Int, name: String)
def insertUser(user: User): Future[Unit] = cql"insert into users(userid, name) values (?, ?)".bind(user).execute
// returns Future[Iterator[User]]
def selectAllUsers: Future[Iterator[User]] = cql"select * from users".all[User]
// if no user is found will throw NoRowsSelectedException
def selectUser(userId: Int) = cql"select * from users where userId = $userId".one[User]
// if no user is found will return None, otherwise Some(User)
def selectUserIfFound(userId: Int) = cql"select * from users where userId = $userId".oneOption[User]
}
To use library in your playframework project, add this line to the build.sbt file:
libraryDependencies += "eu.inn" %% "binders-cassandra" % "0.2.0"