gpt4 book ai didi

scala - slick2.0 : how to make a Table object?

转载 作者:行者123 更新时间:2023-12-01 13:18:16 25 4
gpt4 key购买 nike

您好,我刚刚更新并运行了 simple slick Table,想查询它。

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] 不返回对象???如何解决。

最佳答案

您不能在类或对象定义之外拥有 val。

尝试

object DatabaseContext {
val coffees = TableQuery[Coffees]
}

关于scala - slick2.0 : how to make a Table object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com