如何从 Query[TableType] 或 Query[TableType, EntityType, Seq] 中读取所有实体?在教程中有“结果”方法,但它没有在所有配置之后定义。
编辑:
我尝试使用 qbooks.result 和 (for(book <- qbooks) yield(book)).result 从这个模型:
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)
}
最佳答案
val qbooks = TableQuery[Books]
似乎是一个宏(必须在编译器中启用宏吗?)。我没有使用过这种语法,但以下内容为我编译
//one of the table queries
object qbooks extends TableQuery[Books](tag ⇒ new Books(tag)) {
def all = qbooks.result
}
db.run(qbooks.all)
关于scala - 从光滑的查询中获取所有实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30600038/