CodeLionX / actordb

Actor Database System Framework using Akka
MIT License
0 stars 2 forks source link

Refactor relation creation: introduce RelationDef #58

Closed CodeLionX closed 6 years ago

CodeLionX commented 6 years ago

Proposed Changes

object TestRelation extends RelationDef {
  val col1: ColumnDef[Int] = ColumnDef("col1")
  val col2: ColumnDef[String] = ColumnDef("col2")

  override val columns: Set[UntypedColumnDef] = Set(col1, col2)
  override val name: String = "testRelation"
}

// `RowRelation` can be replaced by any other relational store
val testRelation: MutableRelation = RowRelation(TestRelation)
testRelation.insert(
  TestRelation.newRecord.build(), // preferred
  testRelation.newRecord.build()
)
val records: Relation = testRelation.where(TestRelation.col1 -> { _ == 1 })

Related

CodeLionX commented 6 years ago

Naming Conventions:

Change current

srfc commented 6 years ago

I'm actually not sure if I like the SomethingDef naming for RelationDefs, because when interacting with the Relation, e.g. creating a new Record and using the Relations ColumnDefs, I feel like using RelationDef.ColumnName adds another layer of indirection that I feel is unnecessary. This does not relate to the trait itself as much as the naming of all RelationDefs.

I think I would prefer that, if everything stays the same, the suggested pattern would be

// companion object
object UserInfo extends RelationDef {
  // ...
}

// corresponding Dactor - as is defined in the PR now:
val userInfo: MutableRelation = RowRelation(UserInfo)

override protected val relations: Map[String, MutableRelation] = Map("userInfo" -> userRelation)

override def receive: Receive = Actor.emptyBehavior

rename RowRelation to RowStore?

I think this only really makes sense when we decide to call the technical side of things Store and the definitions "go back" to be called Relation without the Def only. What do you think abou this? Otherwise I think the naming can remain as is.

CodeLionX commented 6 years ago

@srfc I addressed your remarks, I hope this is now ok for you?