[2.0-M2] Problem with MappedColumnType

426 views
Skip to first unread message

Ricardo Franco

unread,
Oct 7, 2013, 2:51:45 PM10/7/13
to scala...@googlegroups.com
i'm converting my code from slick 1 to 2 and i have problem with MappedColumnType when create a trait and extends this.
Follow a piece of code.

import scala.slick.driver.JdbcProfile
trait Profile {
  val profile: JdbcProfile
}
trait TableComponent extends Profile {
  
  abstract class PowerTable[ID <: TypedId, E <: Entity[ID]](tag:Tag, tableName: String)
    extends Table[E](tag, tableName) with HasId[ID] {
 
  }
  trait HasId[ID <: TypedId] {
    self: Table[_] =>
    protected val idColumnName = "id"
    implicit val idMapper: MappedColumnType[ID, Long]
    def id = column[ID](idColumnName, O.AutoInc, O.NotNull)
  }
}
trait AccountTable {
  self: TableComponent =>
  import profile.simple._
  val accountQuery = TableQuery[Accounts]
  class Accounts(tag:Tag) extends PowerTable[AccountId, Account](tag, "accounts")
    with HasId[AccountId] {
    /* Error:
     - could not find implicit value for evidence parameter of type scala.slick.ast.BaseTypedType[AccountId]
     - could not find implicit value for evidence parameter of type scala.slick.jdbc.JdbcType[Long]
     - not enough arguments for method base: (implicit evidence$1: scala.reflect.ClassTag[com.paguemob.gateway.model.AccountId], implicit evidence$2: scala.slick.jdbc.JdbcType[Long])scala.slick.jdbc.JdbcType[AccountId] with scala.slick.ast.BaseTypedType[AccountId]. Unspecified value parameter evidence$2.
     */

    implicit val idMapper = MappedColumnType.base[AccountId, Long](
      i => i.id,
      l => AccountId(l)
    )
    def create = Account.apply _
    def extrator = Account.unapply _
    
    def email = column[String]("email", O.NotNull)
    def * = (email, id.?) <> ( create.tupled, extrator)
  }
}

Any suggestion?

Tks


Reid Spencer

unread,
Oct 8, 2013, 8:04:20 AM10/8/13
to scala...@googlegroups.com
Looks to me like some Specs2 code has crept in here, based on the "evidence parameter" mention in the error. It isn't apparent from the listing how that is happening, but it might be a clue for you.

Ricardo Franco

unread,
Oct 8, 2013, 9:47:27 AM10/8/13
to scala...@googlegroups.com
I didn't understand what you'd like to say.
I'd like to have a trait with abstract mapper and create it in the extended class but i have problem with type.


On Tue, Oct 8, 2013 at 9:04 AM, Reid Spencer <re...@viritude.com> wrote:
Looks to me like some Specs2 code has crept in here, based on the "evidence parameter" mention in the error. It isn't apparent from the listing how that is happening, but it might be a clue for you.

--
 
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Naftoli Gugenheim

unread,
Oct 10, 2013, 7:02:29 PM10/10/13
to scala...@googlegroups.com
"Evidence" just means an implicit arg added by the compiler (e.g. when using context bounds syntactic sugar, or the older view bound syntactic sugar).


On Tue, Oct 8, 2013 at 8:04 AM, Reid Spencer <re...@viritude.com> wrote:
Looks to me like some Specs2 code has crept in here, based on the "evidence parameter" mention in the error. It isn't apparent from the listing how that is happening, but it might be a clue for you.

--

Christopher Vogt

unread,
Oct 13, 2013, 5:31:15 AM10/13/13
to scala...@googlegroups.com
Hi Ricardo,

here is a slightly modified version of your code, what compiles:

https://gist.github.com/cvogt/6953558

I changed the return type of HasId#idMapper. I think you made a mistake
there. Also, I now fetch the implicit JdbcType[Long] for the
MappedColumnType.base outside of class Accounts and pass it in
explicitly. Not sure why that is needed. (I also added some classes you
were referring to, but not including in your example. Please do that
next time :).)

Chris
--
Slick Team

Christopher Vogt

unread,
Oct 13, 2013, 6:09:50 AM10/13/13
to scala...@googlegroups.com
UPDATE: I figured out an appropriate return type annotation to idMapper
in Accounts managed to help the type inferencer enough to figure it out
itself. I updated the gist: https://gist.github.com/cvogt/6953558
Reply all
Reply to author
Forward
0 new messages