This project is a template for a DML statements. Specifically It implements Data Manipulation Statement [INSERT - SELECT]. If you want to implement a project that connects with ** Cassandra ** in an Ecosystem scala and because of its simplicity does not want to have dependencies with any Orm, the use of this template can give you a good starting point for your project.
-
A basic template that implement INSERT and QUERY statements. It contain implementation on test module.
-
How implement TDD in our development process:
- We have create the base of Spec with FlatSpec style: We have NOT covered the whole lines of code but we have created enoguh test suites for give you an idea of how to make with the rest. In our case case we connect to an specific Keyspace - table
- ErrorHandler implementation as indicate play framework specification.
- Internationalization of messages.
- LogHandler:
- Although we register some log, must exist a log handler, which could be a trait. This trait could be implemented by all those classes that, at some point, can generate a log.
- jdk 1.7+ -> how check java version: java -version
- scala 2.11.x -> how check scala version: scala -version
- sbt 0.13.11+ -> how check sbt version: sbt about
- Cassandra 3.3.x+ -> how check sbt version: bin/nodetool version
note: If cassandra is installed as a service, it is NOT necessary to go to the installation directory of cassandra, it will be enough: nodetool version from anywhere in your system.
- clone repository
- go to root project
- call the following script(for Linux [Ubuntu - Centos] or OSX):
Script files are more complex because we need to make several verifications about processes that are running under OS before execute any process. We need to check after every execution what exactly happened before and so on. But if you feel confortable in OSX/Linux terminal you only need to execute in your terminal following lines of code:
You must go to Cassadra installation directory:
- Create keyspace for our test:
## keyspace name
KEYSPACETEST=dbtest
local dd_create_keyspace="CREATE KEYSPACE $KEYSPACETEST WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};"
echo "$dd_create_keyspace" | bin/cqlsh
if the previous process was success:
- Create table for our test:
## table
local dd_create_table="CREATE TABLE dbtest.footballtest (
league int PRIMARY KEY,
awaygoals int,
awaygoalsplayer map<text, text>,
awayteam text,
dategame timestamp,
homegoal int,
homegoalsplayer map<text, text>,
hometeam text,
matchweek text) WITH comment='Contains stats for europe football leagues';"
echo "$dd_create_table" | bin/cqlsh
note: If cassandra is installed as a service in your OS, it is NOT necessary to go to the installation directory of cassandra, so you can replace a piece in the previous lines and instead of bin/cqlsh can use bin/cqlsh. So you can execute the previous line from every where.
For windows users is mandatory and for OSX or Linux users who wish to use the cqlsh console, these are the two commands to be executed from the Cassandra console:
CREATE KEYSPACE dbtest WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};
CREATE TABLE dbtest.footballtest (
league int PRIMARY KEY,
awaygoals int,
awaygoalsplayer map<text, text>,
awayteam text,
dategame timestamp,
homegoal int,
homegoalsplayer map<text, text>,
hometeam text,
matchweek text) WITH comment='Contains test stats ';
Now your environment for work is ready.
This Test suite basically insert a record and then execute a query for get the record inserted previously. You can use this platform for you own objects, only need the appropriate implicit conversions.
- go to root project
- type in terminal: sbt compile test
Each package in the source code has a file (package.txt) that explains the fundamentals of that specific package.
If you want to create your own connections we have here an example of how modify an create your owns configurations objects. Anyway remember that the best way is always by configurations files.
https://mojitoverdeintw.blogspot.com