Quill provides Scala based
Quoted Domain Specific Language(QDSL) which supports compile time query generation and validation. It allows to express queries in Scala and access database similar to Scala collections. Quill is designed to support multiple target languages. At the moment it supports
CQL(Cassandra Query Language).
In this post I’m gonna discuss about using Quill to do query operations with cassandra. In my previous post I have discussed about using cassandra prepared statements with scala. All source codes which relates to this post available on gitlab. Please clone the repository and continue the post.
I have run Cassandra with
Elassandra docker image. Elassandra built by combining Elasticseach with Cassandra. It comes Elasticsearch as a Cassandra plugin. Basically it has Cassandra API as well as Elasticsearch API. When data save on Cassandra it will automatically index on Elasticsearch. Read more about elassandra from here. Following is the
docker-compose.yml to run the elassandra.
Now I can run the Elassandra with following commands. It will start Cassandra on my local machine. I can access the Cassandra via
Cqlsh inside the Elassandra docker container.
In cassandra I have a keyspace named
mystiko and table a named
document. document table contains a
signatures. Following are the schemas.
IntelliJ Idea as my IDE to work with Scala applications. I need to create
sbt project and add the
build.sbt dependency file with
quill-cassandra and other dependencies. Following is the
build.sbt dependency file.
The cassandra configurations defined in
cassandra.conf file. It contains
keyspace etc informations.
These configs load into
CassandraConf.scala trait and use to create the cassandra
Then I have created a cassandra
session which can use to execute queries. I have defined
I have defined the
signatures in cassandra schema as
case class objects. These objects used when creating/querying the documents on cassandra.
document table contains
signature. In order to query signature type I have defined custom
decoder. It converts signature case class objects into UDT signatures and UDT signatures in to signature case class objects.
Then I have defined
DocumentStore which facilitates document
search query functions with Quill.
Finally I have run the
search query functions which defined in
DocumentStore. Following is the
Main application with query outputs.