Search code examples
scalacassandraphantom-dsl

What's wrong with CollectionColumn?


I'm trying out phantom from outworkers following the laidout tut on the wiki.

I'm using a test model:

case class User (id: String, name: String, friends: List[String])

with:

import com.websudos.phantom.dsl._

class Users extends CassandraTable[Users, User] {
  object id extends StringColumn(this) with PartitionKey[String]
  object name extends StringCoumn(this)
  object friends extends ListColumn[String](this)
}

The ListColumn[String]() argument this is marked as an error which I presume I shouldnt even bother to build. Expected CassandraTable[String, User] instead of this.

I'm using version 1.29.6

Am I using a different version from the wiki example? Or missing something else?


Solution

  • This is an InteliJ highlightining problem. ListColumn is defined as a type alias inside Cassandra table, and for all type aliases that take constructor arguments, InteliJ is not capable of seeing through them.

    That aside, I would really upgrade to phantom 2.0.0+, just because of all the new improvements made in 2.0.0. There is quite a bit of work that's gone into fixing errors and reducing how much code you need to type:

    import com.outworkers.phantom.dsl._
    
    class Users extends CassandraTable[Users, User] {
      object id extends StringColumn(this) with PartitionKey
      object name extends StringCoumn(this)
      object friends extends ListColumn[String](this)
    }
    

    In more recent versions of phantom, 2.9.x+, the this argument is no longer required using the new compact DSL.

    import com.outworkers.phantom.dsl._
    
    abtract class Users extends Table[Users, User] {
      object id extends StringColumn with PartitionKey
      object name extends StringColumn
      object friends extends ListColumn[String]
    }