phantom
phantom copied to clipboard
Support table inheritance natively in the DSL
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].
@hsn10 I know you had thoughts here, please feel free to add to the mix.
I need ability to override column type including column used for primary key
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
}