Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support table inheritance natively in the DSL #770

Open
alexflav23 opened this issue Nov 6, 2017 · 3 comments
Open

Support table inheritance natively in the DSL #770

alexflav23 opened this issue Nov 6, 2017 · 3 comments

Comments

@alexflav23
Copy link
Member

alexflav23 commented Nov 6, 2017

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
Copy link
Member Author

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

@hsn10
Copy link

hsn10 commented Dec 5, 2017

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

@somename6668
Copy link

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants