scalacassandraphantom-dsl

Phantom DSL and Cassandra custom column type


I've defined a custom Cassandra type and a table,e.g:

CREATE TYPE my.usertype (
  id text,
  firstname text,
  lastname text
);


CREATE TABLE mytable (
  user frozen <usertype>,
  ...,
  PRIMARY KEY(user)
);

How can I define this user type in the Cassandra table definition in Scala?

class MyTable extends CassandraTable[X, Y] {
  object user extends UserColumn(this) with PartitionKey[User]
                      ^^^^^???                           ^^^???

How can I implement a custom UserColumn for the UserType? I checked the Phantom code for the column implementations, but any example and/or explanation would be great.


Solution

  • In phantom pro only.

    @Udt case class User(
      id: String,
      firstname: String,
      lastname: String
    )
    

    And then you use UDTColumn:

    class MyTable extends Table[MyTable , Y] {
        object user extends Col[User] with PartitionKey
    }
    

    This will give you automated schema generation and whatever else, including automated initialisation of your UDT.