3

こんにちは、単純な滑らかなテーブルを更新して実行し、問い合わせたいと思います。

import scala.slick.driver.PostgresDriver.simple._
import scala.slick.lifted.TableQuery

class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {
  def name = column[String]("COF_NAME", O.PrimaryKey)
  def price = column[Double]("PRICE")
  def * = (name, price)
}
val coffees = TableQuery[Coffees];

エラーは次のとおりです。

[error] C:\testprojects\slickplay\app\model\Coffee.scala:11: expected class or o bject definition
[error] val coffees = TableQuery[Coffees];

TableQuery[Coffees] がオブジェクトを返さない???修正方法を教えてください。

4

3 に答える 3

1

クラスまたはオブジェクト定義の外に val を持つことはできません。

試す

object DatabaseContext {
  val coffees = TableQuery[Coffees]
}
于 2014-03-20T08:13:35.557 に答える
0

object coffees extends TableQuery(new Coffees(_))

于 2014-10-26T11:04:17.063 に答える
0

または、すべてを side trait に入れることもできます。

import scala.slick.driver.PostgresDriver.simple._

trait DomainComponent{

   class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {
     def name = column[String]("COF_NAME", O.PrimaryKey)
     def price = column[Double]("PRICE")
     def * = (name, price)
    }
  val coffees = TableQuery[Coffees];
   } 
于 2014-03-20T18:04:16.727 に答える