kclay / rethink-scala

Scala Driver for RethinkDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add macros to support using Case Classes as the function parmater

kclay opened this issue · comments

(v:Hero) => hero.foo + 10 / 50 + hero.bar
// translates to 
(v:Var)=> v("foo").+(10)./(50).+(v("bar"))

This should be possible with http://www.scala-lang.org/files/archive/nightly/docs/library/index.html#scala.reflect.api.Trees$Transformer

commented

Thanks for you your recent update on json protocol support.

Any update on this issue? Do you see this coming soon?

This is a massive undertaking still not sure how I'm going to do it. I may end up just making a module that allows for something like Slick lifted support,

commented

Maybe able to simply dissect this:
https://github.com/jonifreeman/sqltyped

Adding this for reference. Whether I have time to attack it or someone else takes a stab.

commented

Not the end solution by any means, but nice utility used in the meantime.

Simple macro used to create constructor parameters as strings in companion object.
https://github.com/maohde/scala-macro-template/blob/annotation-example/macro/src/main/scala/Macros.scala

@fieldNames
case class Persion(name: String, age: Int) extends Document

Thus allowing you to use Person.name and Person.age as strings of their corresponding field name.

Now thats a nice find, wonder how it plays with something like

object Person{

 def foo:String
}

case class Person(name:String,age:Int) extends Document
commented

Right now it won't play nice, but I will modify it so it gets the companion object if it exists.

Sounds nice, maybe we can have something like

trait Lifted[T <:Document]{

 .... fields ...


}
val seq:Sequence[Person]
def filter(o:Lifted[T] => Binary)

seq.filter(_.name > 10 )

And have the Lifted class created via implicit macro? My only concern is how to translate it to Var. Top level should be simple but nested needs to follow the path. May need to have an encodeRef or something similar that retains the path so I can be composed to Var easily . Maybe def name:Column[String]. I've been working with slick for a few months, that's why most of the suggestions mimics it hehe.