Giter Site home page Giter Site logo

play-cassandra's Introduction

Play-Cassandra

A Play Plugin for using Cassandra

The Plugin initializes a Cassandra Session on startup and provides access to session and other properties through the Cassandra object.

The Plugin also provides play-evolutions like functionality if it is not disabled.

####Usage In library dependencies, include

"com.tuplejump" %% "play-cassandra" % "1.0.0-SNAPSHOT"

Now, Cassandra host, port, cluster and session can be accessed through the API exposed by the Plugin. In addition to that, a method loadCQLFile is also available. The API is documented at TODO

Some examples,

  • executing a query
val query = QueryBuilder.select("title")
      .from("music", "playlists")
      .where(QueryBuilder.eq("id", playlistId))
    val queryResult = Cassandra.session.execute(query).toIterable
  • executing a batch statement
val insertQuery: String = "INSERT INTO music.playlists (id, song_id, title, artist, album) VALUES (?, ?, ?, ?, ?)"

    val ps = Cassandra.session.prepare(insertQuery)
    var batch = new BatchStatement()

    songs.foreach {
      s =>
        batch.add(ps.bind(playlistId, s.id, s.title, s.artist, s.album))
    }
    Cassandra.session.execute(batch)
  • loading a CQL statements from a file
Cassandra.loadCQLFile("init.CQL")

Note:The cluster and session exposed are closed by the Plugin when the application is stopped.

#####Evolution

Evolution is enabled by default and the file names are expected to be integers in order, similar to play-evolutions for SQL or SQL-like databases.

The configuration property cassandraPlugin.appName should be set when evolution is enabled. The plugin adds an entry for each appName and the default value is appWithCassandraPlugin

To disable evolution, add the following to conf/application.conf,

cassandraPlugin.evolution.enabled=false

Note: The plugin loads before GlobalSettings, so it is accessible in a custom Global object.

####Configuration The default configuration is,

cassandraPlugin {
  //host and port of where Cassandra is running
  host = "127.0.0.1"    
  port = 9042           
  
  evolution {
    enabled = true
    directory = "evolutions/cassandra/" //directory within conf to look for CQL files
  }
  
  appName = "appWithCassandraPlugin" // appName to be saved in DB when using evolutions
}

play-cassandra's People

Contributors

shiti avatar

Stargazers

 avatar Eman Shaaban avatar Peter Rudenko avatar Matt Biddulph avatar

Watchers

 avatar Satyaprakash Buddhavarapu avatar Rohit Rai avatar Aaruna Godthi avatar James Cloos avatar Evan Chan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.