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

Problem with === and Slick #1266

Open
domdorn opened this issue Mar 12, 2024 · 0 comments
Open

Problem with === and Slick #1266

domdorn opened this issue Mar 12, 2024 · 0 comments

Comments

@domdorn
Copy link
Contributor

domdorn commented Mar 12, 2024

Hi,

I have a problem which I cannot find the answer to: As soon as I have a prelude Newtype used anywhere in a file, preludes === implicit kicks in and hides the === Operator defined in Slick that are used to lift ordinary values to a Rep[A].
I have not imported anything from prelude in the file, its enough that a parameter in a method is a Newtype.

e.g. the code works, when "projectId" is a UUID:

case class BerechnungsstueckPersistenceSPIImpl (database: Database) extends BerechnungsstueckPersistenceSPI with DBFailureMixin {
  import com.acme.project.adapters.outbound.persistence.slick.DomainIdImplicits._
  import com.acme.project.adapters.outbound.persistence.PostgresProfile.api._


  val berechnungsstuecke: TableQuery[Berechnungsstuecke] = TableQuery[Berechnungsstuecke]
  override def getBerechnungsstueckeForProject(projectId: UUID)(implicit c: CorrelationId): ZIO[Any, Failure, List[Berechnungsstueck]] = {
    val query = berechnungsstuecke.filter(_.projectId.===(projectId)).result

    ZIO.fromFuture(_ => {
        implicit val ec: ExecutionContext = database.db.executor.executionContext
        database.db.run(query)
      }
      ).map(l => l.map(v => Berechnungsstueck(v.id, v.from, v.to, v.enabled)).toList)
      .mapError(e => handleFailure(e))

  }

grafik
grafik

but if I change projectId to be a object ProjectId extends zio.prelude.Newtype[UUID], the === operator is using the implicit in zio.prelude.EqualSyntax.EqualOps#===

e.g. if the class looks like this:

case class BerechnungsstueckPersistenceSPIImpl (database: Database) extends BerechnungsstueckPersistenceSPI with DBFailureMixin {
  import com.acme.project.adapters.outbound.persistence.slick.DomainIdImplicits._
  import com.acme.project.adapters.outbound.persistence.PostgresProfile.api._


  val berechnungsstuecke: TableQuery[Berechnungsstuecke] = TableQuery[Berechnungsstuecke]
  def getBerechnungsstueckeForProjectNewtype(projectId: ProjectId)(implicit c: CorrelationId): ZIO[Any, Failure, List[Berechnungsstueck]] = {
    val query = berechnungsstuecke.filter(_.projectId.===(projectId)).result

    ZIO.fromFuture(_ => {
        implicit val ec: ExecutionContext = database.db.executor.executionContext
        database.db.run(query)
      }
      ).map(l => l.map(v => Berechnungsstueck(v.id, v.from, v.to, v.enabled)).toList)
      .mapError(e => handleFailure(e))

  }

grafik
grafik

Is there a way to disable this?

Thanks,
Dominik

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

1 participant