【发布时间】:2021-04-29 21:02:22
【问题描述】:
如何在 slick 3.0.0 中从 Query[TableType] 或 Query[TableType, EntityType, Seq] 中读取所有实体?教程中有“result”方法,但在所有配置后都没有定义。
编辑:
我已尝试使用此模型的 qbooks.result 和 (for(book
import java.sql.Date
import slick.driver.H2Driver.api._
import slick.backend.DatabasePublisher
import slick.driver.JdbcProfile
import entities._
object tables {
private val db = Database.forConfig("h2db")
//one of the table queries
val qbooks = TableQuery[Books]
db.run(
DBIO.seq(
qbooks.schema.create,
...
)
)
//one of the tables
class Books(tag: Tag) extends Table[Book](tag, "books") {
def isbn = column[Int]("isbn", O.PrimaryKey, O.AutoInc)
def author = column[String]("author")
def title = column[String]("title")
def year = column[Int]("edition_year")
def amount = column[Int]("amount")
def * = (isbn, author, title, year, amount) <>
(Book.tupled, Book.unapply)
}
【问题讨论】:
-
您仍应使用结果方法。可能是您的 IDE 无法推断结果方法存在。 IntelliJ 有(或最近有)这个问题。 youtrack.jetbrains.com/issue/SCL-8436。您是否尝试过在 IDE 之外进行编译?
-
仍然存在:“值结果不是 slick.lifted.TableQuery[TTable] 的成员”和“值结果不是 slick.lifted.Query[TTable, Entity,Seq] 的成员。 "
-
您可以发布更多代码吗?