zio-protoquill
zio-protoquill copied to clipboard
Using library with ZIO service pattern
Version: (e.g. 4.6.0.1) **Module**: (e.g.
quill-jdbc) **Database**: (e.g.
postgres`)
I'm trying to use Protoquill as part of the ZIO service (https://zio.dev/reference/service-pattern/introduction/), just as I did with Quill for Scala 2. However, I have a compilation problem, which is probably due to a macro or inline function (I have not experienced this problem, using Quill).
Before I extend the trait, which is a ZIO service, everything works as expected, example code, which works:
private case class UserRepositoryDoobiePostgres() extends BasePostgresRepository {
import doobieContext.*
inline def xxxx(userEntity: UserEntity) = run(quote(users.insertValue(lift(userEntity))))
inline def createUser(user: User): ZIO[Connection, DbException, User] = for {
now <- Clock.instant
entity = UserEntity(user.id.value, user.email.toString, now)
_ <- tzio(run(quote(xxxx(entity))))
} yield user
inline def users = querySchema[UserEntity](UserRepository.Tables.users)
}
But if I extend the trait, like (changed extends, and addred override):
private case class UserRepositoryDoobiePostgres() extends UserRepository with BasePostgresRepository {
import doobieContext.*
inline def xxxx(userEntity: UserEntity) = run(quote(users.insertValue(lift(userEntity))))
inline override def createUser(user: User): ZIO[Connection, DbException, User] = for {
now <- Clock.instant
entity = UserEntity(user.id.value, user.email.toString, now)
_ <- tzio(run(quote(xxxx(entity))))
} yield user
inline def users = querySchema[UserEntity](UserRepository.Tables.users)
}
I received the following compilation error:
error] 37 | inline override def createUser(user: User): ZIO[Connection, DbException, User] = for {
[error] | ^
[error] | Could not summon a parser factory
[error] |----------------------------------------------------------------------------
[error] |Inline stack trace
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |This location contains code that was inlined from UserRepository.scala:37
[error] 35 | inline def xxxx(userEntity: UserEntity) = run(quote(users.insertValue(lift(userEntity))))
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |This location contains code that was inlined from UserRepository.scala:37
[error] 40 | _ <- tzio(run(quote(xxxx(entity))))
[error] | ^^^^^^^^^^^^
[error] ----------------------------------------------------------------------------
@getquill/maintainers
I can also set methods as inline in trait, but this will require that almost the entire application has inline functions. I wonder if it's possible to limit this to just the database part.
Hi @PawelJ-PL, wondering if you came to a solution here?
Yes, I found solution. As I remember, i fixed it by importing import io.getquill.*
or importing quill methods from context (I can't remember, but I fixed it using proper import)