Open strelec opened 10 years ago
The way to get it working is to create implicits in the driver class. However, that is unintuitive. If possible, code should be changed to use above implicit instead.
trait MyArrayImplicits extends ArrayImplicits {
implicit val cardWrapper = new SimpleArrayListJdbcType[Card]("smallint").basedOn[Short](
Deck.full.indexOf(_).toShort,
pos => Deck.full.apply(pos.toShort)
)
}
@strelec card[]
is different type to card
, that's why we should declare a type mapper for card[]
.
But, if you mean, why slick-pg
not to declare an array type mapper automatically for you based on existing base type mapper when necessary?
The answer is, it can but it shouldn't, since we shouldn't create too much duplicated type mapper instances.
But, of course, if a way that can automatically create single array type mapper was found, we should employ it.
Ok, let's resolve this bug, too. The problem is the duplication of code.
object Card {
import play.api.db.slick.Config.driver.simple._
implicit val mapper = MappedColumnType.base[Card, Byte](
Deck.full.indexOf(_).toByte,
pos => Deck.full(pos)
)
}
trait MyArrayImplicits extends ArrayImplicits {
implicit val cardWrapper = new SimpleArrayListJdbcType[Card]("smallint").basedOn[Byte](
Deck.full.indexOf(_).toByte,
pos => Deck.full(pos)
)
}
There is clearly a duplication of logic present. What do you think?
As we know, in general a static object should be hold by a val
variable, so it's difficult to generate a type mapper dynamically and keep it static at the same time.
And, from my opinion, if a little inconvenience from super user, who setup environment for a project and ease other team members, can bring up obvious performance improvement, it doesn't matter.
So if we can't find a simple way to resolve this problem, I'd like to leave it go.
Card
class has properMappedColumnType
in scope.List[List[...]]
works. Does it?