How to Manage Android Devices? A guide for TV Operators

Android TV and Google TV are becoming more and more popular with each passing day. Android TV-powered Set-top Boxes (STBs) are also becoming quite common in the TV Operator industry, going so far as…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Getting Started With Phantom

Phantom is Reactive type-safe Scala driver for Apache Cassandra/Datastax Enterprise. So, first lets explore what Apache Cassandra is with some basic introduction to it.

We wanted to integrate Cassandra into Scala ecosystem that’s why we used Phantom-DSL as one of the module of outworkers. So, if you are planning on using Cassandra with Scala, phantom is the weapon of choice because of :-

You don’t need to switch to CQL(Cassandra Query Langguage) to create keyspace in Cassandra.

So, for that first you need to add up the dependency into yout project :-

You need to import this by default in your code:-

Now, you can connect to Cassandra cluster by creating a ContactPoint called Connector which is basically required to run the application. when we start creating databases, we pass in a ContactPoint or what we call a connector in more plain English.

You have added the dependency and connected to your Cassandra cluster now, You are ready to create your very first table. Let’s assume we are modelling the CQL schema for a case class that looks like this:-

Here’s how the Phantom DSL code looks like:-

where Users is the table and User is the case class. All the fields with their column type has been defined. There must be atleast one field which must be a Partition Key same as a Primary Key in SQL. Partition key tells how your data is partitioned across the cluster.

Earlier, we were using CassandraTable trait instead of Table trait that we have mentioned in the above Phantom DSL code. By extending Table trait you don’t need to extend the RootConnector explicitly as Table trait already extends CassandraTable with RootConnector.

So, the question is Why we needed to define RootConnector?

The simple answer for it is RootConnector defines the Keyspace and Session for you. It tells the table a connector with a `session` and `keySpace` will be injected later on.

You have created Keyspace and a table now, its time to insert data into the Cassandra table. You can do this by writing the below code snippet into the class Users.scala.

For quering your table, to get the data out of the table as needed by using various clauses and operators. Here, is the small code snippet :-

Hope you liked the blog. Happy coding!! :)

knoldus-advt-sticker

Add a comment

Related posts:

Designing Education with Embodied Learning in Mind

5 questions to share my vision regarding Embodied Learning and the role it plays in one’s development. keywords: #embodiedlearning #expression #spatialcomputing

Simplicity After Complexity

There are a few basics that have been important ingredients to my self-liberation. For instance, wine has always produced better insight than whiskey. When the exhausting training program of…

How to Find New Up and Coming Fashion Brands

The struggle to find new brands to keep your wardrobe fresh and updated is always a struggle. There are many ways to find new brands like going on online publication websites like Refinery29’s…