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

Fix slick's proven shape problems #6

Open
luksow opened this issue May 19, 2017 · 2 comments
Open

Fix slick's proven shape problems #6

luksow opened this issue May 19, 2017 · 2 comments

Comments

@luksow
Copy link
Contributor

luksow commented May 19, 2017

case class Member(id: UUID, name: String)

object Member {
  
}

class Members(tag: BaseTable.Tag) extends BaseTable[Member](tag, "position") {
  import driver.api._

  def id: Rep[UUID]                             = column[UUID]("id")
  def name: Rep[String]                             = column[String]("name")

  override def * : ProvenShape[Member] =
    (id, name) <> (Member.tupled, Member.unapply)
}

This does not compile for obvious reasons and needs a change to (id, name) <> ((Member.apply _).tupled, Member.unapply).

Even worse, let's consider this:

case class MemberCreateRequest(name: String)

case class Member(id: UUID, name: String)

object Member {
  def apply(request: MemberCreateRequest): Member = Member(UUID.randomUUID(), request.name)
}

class Members(tag: BaseTable.Tag) extends BaseTable[Member](tag, "position") {
  import driver.api._

  def id: Rep[UUID]                             = column[UUID]("id")
  def name: Rep[String]                             = column[String]("name")

  override def * : ProvenShape[Member] =
    (id, name) <> ((Member.apply _).tupled, Member.unapply)
}

It won't compile again due to ambiguous reference.

Can kebs help with that?

@marcin-rzeznicki
Copy link
Contributor

I think we can automatically generate * override based on case-class and column structure in the table, if that's what's on your mind. But for this to be complete (eg. no red squiggles in IntelliJ), I believe we should introduce scala-meta based solution. I was thinking of a few cases where we would need scala-meta anyway eg. generation of Free / tagless patterns. Stay tuned

@luksow
Copy link
Contributor Author

luksow commented Jun 20, 2017

That would be fancy but the main thing I want to avoid is ambiguity of the second example. It's not a problem for me to write:

override def * : ProvenShape[Member] = (id, name) ~> ohMightKebsPleaseHelp()

Besides that I guess it's nearly impossible to generate that if you have nested case classes in proven shape.

@luksow luksow added the medium label Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants