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

或者你可以把所有东西都放在侧面特征中:

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 回答
0

对象咖啡扩展 TableQuery(新咖啡(_))

于 2014-10-26T11:04:17.063 回答