(I'm a complete beginner with Scala and Slick, so code review of any kind is appreciated)
I have the following class
and Slick Table
defined:
case class Foo(title: String, description: String, id: Int = 0)
class FooTable(tag: Tag) extends Table[Foo](tag, "FOO") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def title = column[String]("TITLE", O.NotNull)
def description = column[String]("DESCRIPTION")
def * = (title, description, id) <> (Foo.tupled, Foo.unapply)
}
I want to add a method which will return a List
of Foo
s which match a specified title
. Something like this:
def findByTitle(title: String) = DB.withSession { implicit s: Session =>
<FooTable TableQuery>.filter(_.title === title)
}
I'd then be able to use the method like this:
val foos = TableQuery[FooTable]
DB.withSession { implicit s: Session =>
val anId = foos.findByTitle("bar")
}
How/where can I add a method which can act on a TableQuery
for a particular Table
? Is this even the correct way to be arranging my application?