Slick:未找到 TableQuery [SomeType].result
Slick: TableQuery[SomeType].result not found
我遇到了类似于
的问题
但我使用的是 scala 2.11.1、slick 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]
}
我尝试运行一个简单的查询来获取数据库中的所有元素:
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] 的成员。有什么想法吗?
我猜你只是忘了导入 slick 配置文件 api。你的情况:
import slick.jdbc.PostgresProfile.api._
我遇到了类似于
但我使用的是 scala 2.11.1、slick 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]
}
我尝试运行一个简单的查询来获取数据库中的所有元素:
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] 的成员。有什么想法吗?
我猜你只是忘了导入 slick 配置文件 api。你的情况:
import slick.jdbc.PostgresProfile.api._