Slick:找不到TableQuery [SomeType] .result

时间:2017-04-04 14:51:01

标签: postgresql scala slick-3.0

我遇到的问题类似于this

但我使用的是scala 2.11.1,光滑的3.2.0,并使用SBT手动编译,而不是使用IntelliJ。

我为数据库定义了一个dntity:

case class ScheduleItem(id:Option [Int],cron:String,script:String,created_at:Long,updated_at:Long,created_by:String,updated_by:String)

object ScheduleItems {

  class ScheduleItemsT(tag: Tag) extends Table[ScheduleItem](tag, "schedule_items") {

    def id = column[Int]("id", O.PrimaryKey, O.AutoInc)

    def cron = column[String]("column")

    def script = column[String]("script")

    def created_at = column[Long]("created_at", SqlType("timestamp without time zone"))

    def updated_at = column[Long]("updated_at", SqlType("timestamp without time zone"))

    def created_by = column[String]("created_by")

    def updated_by = column[String]("updated_by")

    def * = (id.?, cron, script, created_at, updated_at, created_by, updated_by) <> (ScheduleItem.tupled, ScheduleItem.unapply)
  }

  val table = TableQuery[ScheduleItemsT]
}

我尝试运行一个简单的查询来获取databsae中的所有元素:

db.run(ScheduleItems.table.result)

编译时,这是SBT输出:

[info] Loading project definition from /home/claudino/Projetos/Testes/Agendador2_0/project
[info] Set current project to Agendador2_0 (in build file:/home/claudino/Projetos/Testes/Agendador2_0/)
[info] Compiling 3 Scala sources to /home/claudino/Projetos/Testes/Agendador2_0/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.1. Compiling...
[info]   Compilation completed in 10.646 s
[error] /home/claudino/Projetos/Testes/Agendador2_0/src/main/scala/com/webradar/qns/Main.scala:13: value result is not a member of slick.lifted.TableQuery[com.webradar.Main.schedule.model.ScheduleItems.ScheduleItemsT]
[error]     db.run(ScheduleItems.table.result)
[error]                                ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 13 s, completed 04/04/2017 11:42:20

也就是说,与光滑的3.20文档不同,结果不是TableQuery [SomeType]的成员。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

我猜你只是忘了导入光滑的配置文件api。在你的情况下:

import slick.jdbc.PostgresProfile.api._