I understand how this is done when using types such as Long, Int, String
etc.. But say I have a class that has fields within another class like so:
case class Foo(a:String, b:String)
case class Bar(foo:Option[Foo], c:String)
How would I set up a mapper for my custom type (the Foo
in my Bar
class)?
class Bars(tag:Tag) extends Table[Bar](tag, "BARS") {
def foo = column[Foo]("FOO") // <- won't work
def c = column[String]("C")
def * = (foo, c) <> (Bar.tupled, Bar.unapply)
}
(documentation link)
Update:
DB Driver: slick.driver.PostgresDriver
Slick 2
I'm guessing the raw SQL would look like this:
"BARS" (
"A" VARCHAR(254) NOT NULL,
"B" VARCHAR(254) NOT NULL,
"C" VARCHAR(254) NOT NULL
);
Should be able to call Bar
like so:
val bar = Bar(Foo("1", "2"), "3")
barTable.insert(bar)
bar.foo.a // 1
bar.foo.b // 2
bar.c // 3