Following code works as expected (Laptop is a case class) :
def main(args: Array[String]):
implicit val ctx = new SqlMirrorContext(MirrorSqlDialect, Literal)
import ctx._
val laptops = quote {
querySchema[Laptop]("laptops")
}
implicit val laptopInsertMeta = insertMeta[Laptop](_.id)
val q = quote {
laptops.insert(lift(Laptop(...)))
}
ctx.run(q)
}
But this (on-the-way-to-refactoring) version fails to compile:
class LaptopDaoQuill[I <: Idiom, N <: NamingStrategy](implicit ctx: Context[I, N]) {
import ctx._
def insert(obj: Laptop) = {
val laptops = quote {
querySchema[Laptop]("laptops")
}
implicit val personInsertMeta = insertMeta[Laptop](_.id)
val q = quote {
laptops.insert(lift(obj))
}
ctx.run(q)
}
}
object Main {
def main(args: Array[String]): Unit = {
implicit val ctx = new SqlMirrorContext(MirrorSqlDialect, Literal)
val laptopDao = new LaptopDaoQuill
laptopDao.insert(Laptop(...))
}
With following errors:
Error:(29, 55) Can't find implicit Encoder[Long]
. Please, do one of the following things:
1. ensure that implicit Encoder[Long]
is provided and there are no other conflicting implicits;
2. make Long
Embedded
case class or AnyVal
.
implicit val personInsertMeta = insertMetaLaptop
Error:(32, 21) Can't find an implicit InsertMeta
for type com.training.entity.Laptop
laptops.insert(lift(obj))
Would work in that case (sure with PostgresJdbcContext in main):
class LaptopDaoQuill[N <: NamingStrategy : TypeTag](implicit ctx: PostgresJdbcContext[N]) {...}
BUT not if :
class LaptopDaoQuill[I <: Idiom : TypeTag, N <: NamingStrategy: TypeTag](implicit ctx: Context[I, N])
Thanks in advance!