(我是 Scala 和 Slick 的完整初学者,因此感谢任何形式的代码审查)
我定义了以下内容class
并定义了 Slick Table
:
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)
}
我想添加一个方法,该方法将返回与指定匹配List
的s 。像这样的东西:Foo
title
def findByTitle(title: String) = DB.withSession { implicit s: Session =>
<FooTable TableQuery>.filter(_.title === title)
}
然后我就可以使用这样的方法:
val foos = TableQuery[FooTable]
DB.withSession { implicit s: Session =>
val anId = foos.findByTitle("bar")
}
我如何/在哪里可以添加一个可以对TableQuery
特定对象起作用的方法Table
?这甚至是安排我的申请的正确方法吗?