(私は 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
を返すメソッドを追加したいと考えています。このようなもの: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
ますか? これは私のアプリケーションを手配する正しい方法ですか?