Table Builder

Given a KeySpace it is possible to define a Table by using the provided dsl.

Example

Given a simple table definition (must be a case class):

import java.util.UUID
import shapeless.tag._
import spinoco.fs2.cassandra.CType.Type1

case class SimpleTable (
  intColumn: Int,
  longColumn: Long,
  stringColumn: String,
  timeUuidColumn: UUID @@ Type1
)

We can define a Table with partition:

import spinoco.fs2.cassandra.KeySpace

val ks = new KeySpace("test_ks")

val t1 = {
  ks.table[SimpleTable]
    .partition('intColumn)
    .build("test_table")
}
t1.cqlStatement
// res0: Seq[String] = List(CREATE TABLE test_ks.test_table (intColumn int,longColumn bigint,stringColumn varchar,timeUuidColumn timeuuid, PRIMARY KEY ((intColumn))))

Another one with partition and cluster:

val t2 = {
  ks.table[SimpleTable]
    .partition('intColumn)
    .cluster('longColumn)
    .build("test_table")
}
t2.cqlStatement
// res1: Seq[String] = List(CREATE TABLE test_ks.test_table (intColumn int,longColumn bigint,stringColumn varchar,timeUuidColumn timeuuid, PRIMARY KEY ((intColumn),longColumn)))

And another with index:

val t3 = {
  ks.table[SimpleTable]
    .partition('intColumn)
    .indexBy('stringColumn, "str_idx")
    .build("test_table")
}
t3.cqlStatement
// res2: Seq[String] = List(CREATE TABLE test_ks.test_table (intColumn int,longColumn bigint,stringColumn varchar,timeUuidColumn timeuuid, PRIMARY KEY ((intColumn))), CREATE INDEX str_idx ON test_ks.test_table (stringColumn))