Query Builder
The Query DSL provides methods such as all
, column
, partition
and cluster
which will generate the correspoding CQL statement.
Query DSL
Given our SimpleTable definition we can create different queries.
All
val q1 = t1.query.all.build
q1.cqlStatement
// res0: String = SELECT intColumn,longColumn,stringColumn,timeUuidColumn FROM test_ks.test_table
Column
val q2 = t1.query.column('stringColumn).build
q2.cqlStatement
// res1: String = SELECT stringColumn FROM test_ks.test_table
Column with alias
val q3 = t1.query.columnAs('stringColumn, "my_alias").build
q3.cqlStatement
// res2: String = SELECT stringColumn AS my_alias FROM test_ks.test_table
Function: Count
import spinoco.fs2.cassandra.functions
val q4 = t1.query.function(functions.count, "rows_count").build
q4.cqlStatement
// res3: String = SELECT count(*) AS rows_count FROM test_ks.test_table
Function: DateOf
val q5 = t1.query.functionAt(functions.dateOf, 'timeUuidColumn, "time_of_uuid").build
q5.cqlStatement
// res4: String = SELECT dateOf(timeUuidColumn) AS time_of_uuid FROM test_ks.test_table
Function: UnixTimestampOf
val q6 = t1.query.functionAt(functions.unixTimestampOf, 'timeUuidColumn, "timestamp_of_uuid").build
q6.cqlStatement
// res5: String = SELECT unixTimestampOf(timeUuidColumn) AS timestamp_of_uuid FROM test_ks.test_table
Function: WriteTimeOf
val q7 = t1.query.functionAt(functions.writeTimeOfMicro[String], 'stringColumn, "write_time_of").build
q7.cqlStatement
// res6: String = SELECT WRITETIME(stringColumn) AS write_time_of FROM test_ks.test_table
Function: TTLOf
val q8 = t1.query.functionAt(functions.ttlOf[String], 'stringColumn, "ttl_of").build
q8.cqlStatement
// res7: String = SELECT TTL(stringColumn) AS ttl_of FROM test_ks.test_table
Partition
val q9 = t1.query.column('stringColumn).partition.build
q9.cqlStatement
// res8: String = SELECT stringColumn FROM test_ks.test_table WHERE intColumn = :intColumn
Partition and Cluster
import spinoco.fs2.cassandra.Comparison
val q10 = t2.query.all.partition.cluster('longColumn, Comparison.GTEQ).build
q10.cqlStatement
// res9: String = SELECT intColumn,longColumn,stringColumn,timeUuidColumn FROM test_ks.test_table WHERE intColumn = :intColumn AND longColumn >= :longColumn
Limit
val q11 = t1.query.all.limit(1).build
q11.cqlStatement
// res10: String = SELECT intColumn,longColumn,stringColumn,timeUuidColumn FROM test_ks.test_table LIMIT 1
Allow Filtering
val q12 = t1.query.all.allowFiltering.build
q12.cqlStatement
// res11: String = SELECT intColumn,longColumn,stringColumn,timeUuidColumn FROM test_ks.test_table WITH ALLOW FILTERING
Order By
val q13 = t2.query.all.orderBy('longColumn, ascending = true).build
q13.cqlStatement
// res12: String = SELECT intColumn,longColumn,stringColumn,timeUuidColumn FROM test_ks.test_table ORDER BY longColumn ASC