phantom icon indicating copy to clipboard operation
phantom copied to clipboard

Support table inheritance natively in the DSL

Open alexflav23 opened this issue 7 years ago • 3 comments

As requested by multiple users, we should natively support table inheritance as many applications seem to require it as a simplification of the DSL code, instead of trying to discourage it.

Draft proposal.

  • Table inheritance should be natively possible in the DSL with no additional work.
  • Inherited columns should have order precedence. Inherited columns will be inserted before the "current" columns in the generated Cassandra code. A table appending a partition key for instance, will cause the new key to be added as the last in the sequence of partition keys. This is important in Cassandra so an order should be agreed upfront.
  • One example is [here|https://gist.github.com/jalaziz/f7f5030172acfccafb46a5d239975924].

alexflav23 avatar Nov 06 '17 10:11 alexflav23

@hsn10 I know you had thoughts here, please feel free to add to the mix.

alexflav23 avatar Nov 06 '17 10:11 alexflav23

I need ability to override column type including column used for primary key

hsn10 avatar Dec 05 '17 17:12 hsn10

The code below is how I implemented table inheritance to change PartitionKey and ClusteringOrder setting on different table.

import com.outworkers.phantom.dsl._

case class User(userId: String,
                gender: Int,
                birthDate: DateTime)
trait UserTable[Owner <: Table[Owner, User] with UserTable[Owner]] extends Table[Owner, User] {
  def name: StringColumn

  def gender: IntColumn

  def birthDate: DateTimeColumn

  // def query(): Future[ListResult[User]]
}


abstract class UserByGender extends UserTable[UserByGender] {

  object name extends StringColumn

  object birthDate extends DateTimeColumn

  object gender extends IntColumn with PartitionKey

}

abstract class UserByBirthDate extends UserTable[UserByBirthDate] {

  object name extends StringColumn

  object gender extends IntColumn

  object birthDate extends DateTimeColumn with ClusteringOrder with Descending

}

somename6668 avatar Dec 02 '19 06:12 somename6668