Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

3/14/2019

Reading time:1 min

iamthiago/cassandra-phantom

by John Doe

This project will give you the idea on how to design your cassandra tables in scala using the phantom-dsl. My inspiration is to bring here a more real world example based on this library.Connect to a secure Cassandra ClusterIn the class Connector you will find a connector that connects to a Cassandra ClusterSet Consistency LevelPhantom-DSL offers to you an easy way to set the consistency level for any query you want to execute. You can set that for each query. You can see an example of it in the following classes: SongsModel and SongsByArtistModel. You will find this piece of code .consistencyLevel_=(ConsistencyLevel.ONE) where you can change it to whatever you want, accordingly to your needs.Handle queries for multiple tablesThis is maybe the main goal of this project, showing to you how to handle multiple versions of the same table. Here we have:SongsSongsByArtistYou will find how to insert and delete on both tables.RequirementsThis project uses docker in order to get up and running a cassandra instance.TestingWe are using the official cassandra docker image to setup a simple host.For convenience we are using Makefile where you will find the following commands:- make cassandra/run This command starts a cassandra instance in your localhost and name it as cassandra-phantom. You can see it using the `docker ps` command. - make cassandra/clean It removes the existing image from your docker. - make cassandra Runs both command in sequence.If you don't know Makefile, please check the links below on the Resources section.After that you can test using sbt test.ThanksSpecial thanks to Flavian who have helped me to find out the best way to use phantom to model our Cassandra tables.

Illustration Image

Build Status

This project will give you the idea on how to design your cassandra tables in scala using the phantom-dsl. My inspiration is to bring here a more real world example based on this library.

Connect to a secure Cassandra Cluster

In the class Connector you will find a connector that connects to a Cassandra Cluster

Set Consistency Level

Phantom-DSL offers to you an easy way to set the consistency level for any query you want to execute. You can set that for each query. You can see an example of it in the following classes: SongsModel and SongsByArtistModel. You will find this piece of code .consistencyLevel_=(ConsistencyLevel.ONE) where you can change it to whatever you want, accordingly to your needs.

Handle queries for multiple tables

This is maybe the main goal of this project, showing to you how to handle multiple versions of the same table. Here we have:

  • Songs
  • SongsByArtist

You will find how to insert and delete on both tables.

Requirements

This project uses docker in order to get up and running a cassandra instance.

Testing

We are using the official cassandra docker image to setup a simple host.

For convenience we are using Makefile where you will find the following commands:

- make cassandra/run
    This command starts a cassandra instance in your localhost and name it as cassandra-phantom.
    You can see it using the `docker ps` command.
    
- make cassandra/clean 
    It removes the existing image from your docker.
    
- make cassandra 
    Runs both command in sequence.

If you don't know Makefile, please check the links below on the Resources section.

After that you can test using sbt test.

Thanks

Special thanks to Flavian who have helped me to find out the best way to use phantom to model our Cassandra tables.

Related Articles

migration
proxy
datastax

GitHub - datastax/zdm-proxy: An open-source component designed to seamlessly handle the real-time client application activity while a migration is in progress.

datastax

11/1/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

datastax