Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using library with ZIO service pattern #269

Open
PawelJ-PL opened this issue May 14, 2023 · 3 comments
Open

Using library with ZIO service pattern #269

PawelJ-PL opened this issue May 14, 2023 · 3 comments

Comments

@PawelJ-PL
Copy link

PawelJ-PL commented May 14, 2023

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

@PawelJ-PL
Copy link
Author

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.

@Yomanz
Copy link

Yomanz commented Feb 11, 2024

Hi @PawelJ-PL, wondering if you came to a solution here?

@PawelJ-PL
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants