-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/12/2013 04:02 AM, Leon Radley wrote:
> *My question is* how should I do the mapping of the columns so that
> they correctly get converted into their respective case classes?
I could easily be misunderstanding, but it strikes me that you could
use functions other than Foo.apply and Foo.unapply when using the <>
operator.
Say you had
case class Bar(x: Int, y: Int)
case class Baz(a: Int, b: Int, c: Int)
case class Foo(bar: Bar, baz: Baz)
and a table where a Foo is stored flattened into a row with 5 columns,
you could define your own functions that pack and unpack a Foo, like:
object MyTable extends Table[Foo]("my_table") {
def x = column[Int]("x")
def y = column[Int]("y")
def a = column[Int]("a")
def b = column[Int]("b")
def c = column[Int]("c")
def makeFoo(x: Int, y: Int, a: Int, b: Int, c: Int): Foo = {
Foo(Bar(x, y), Baz(a, b, c))
}
def unpackFoo(foo: Foo): (Int, Int, Int, Int, Int) = {
val Foo(Bar(x, y), Baz(a, b, c)) = foo
(x, y, a, b, c)
}
//not sure if _ is needed here, but you get the gist
override def * = x ~ y ~ a ~ b ~ c <> (makeFoo _, unpackFoo _)
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined -
http://www.enigmail.net/
iEYEARECAAYFAlFA5dUACgkQ5IyIbnMUeTunVwCdE9wDYzM7oYrXAuOedJcXPodU
yogAn1t0Qb1RMv7J6EklW2i7/v7Q4L+F
=IzAJ
-----END PGP SIGNATURE-----