Hi so I've been trying to create some generic functions using macros and Quill.
Here is my implementation of the macro:
class Impl(val c: Context) {
import c.universe._
def all[T](tblName: Tree, ctx: Tree)(implicit t: WeakTypeTag[T]): Tree =
q"""
import ${ctx}._
implicit val schema = schemaMeta[$t](${tblName})
run(quote {
query[$t]
})
"""
}
object Macros {
def all[T](tblName: String, ctx: MysqlAsyncContext[Literal.type]): Future[List[T]] = macro Impl.all[T]
}
And I've tried using it in the below code:
case class Language(id: Short, iso639_1: String, name: String)
object Language {
val tableName = "Languages"
def all()(implicit mysql: MysqlAsyncContext[Literal.type], ec: ExecutionContext): Future[List[Language]] =
Macros.all[Language](tableName, mysql)
}
But then I get the following error:
Language.scala:99:25: type mismatch;
[error] found : mysql.Quoted[mysql.EntityQuery[Language]]{def quoted: io.getquill.ast.Entity; def ast: io.getquill.ast.Entity; def id1101286793(): Unit; val liftings: Object}
[error] required: io.getquill.MysqlAsyncContext[io.getquill.Literal.type]#EntityQuery[com.github.pokeboston.libghpagesapi.normalized.Language]
[error] Macros.all[Language]("Languages", mysql)
[error] ^
However I know that the ctx being passed to the macro is indeed a MysqlAsyncContext because when I change the macro code to:
class Impl(val c: Context) {
import c.universe._
def all[T](tblName: Tree, ctx: Tree)(implicit t: WeakTypeTag[T]): Tree =
q"""
import ${ctx}._
implicit val schema = schemaMeta[$t](${tblName})
$ctx
"""
}
It gives me this following error:
Language.scala:99:25: type mismatch;
[error] found : io.getquill.MysqlAsyncContext[io.getquill.Literal.type]
[error] required: scala.concurrent.Future[List[Language]]
[error] Macros.all[Language]("Languages", mysql)
[error] ^
I'm guessing that there is something with macros that I am fundamentally misunderstanding. Any enlightenment would be much appreciated!
Thanks!
Followed by quill-example I created project on github, see quill-generic
Example from sync implementation:
AbstractCrudMacro.scala
CrudMacro.scala
CrudWithContext.scala
Example of implementation: ConfigurationRepository.scala
Missing types you will find on github repository quill-generic