kclay / rethink-scala

Scala Driver for RethinkDB
Other
100 stars 24 forks source link

Add macros to support using Case Classes as the function parmater #9

Open kclay opened 10 years ago

kclay commented 10 years ago
(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

ohde commented 10 years ago

Thanks for you your recent update on json protocol support.

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

kclay commented 10 years ago

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,

ohde commented 10 years ago

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.

ohde commented 9 years ago

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.

kclay commented 9 years ago

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
ohde commented 9 years ago

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

kclay commented 9 years ago

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.