如何从查询[TableType]或从光滑3.0.0中的查询[TableType,EntityType,Seq]读取所有实体?在教程中有“result”方法,但在所有配置之后都没有定义。
编辑:
我试过使用qbooks.result和(for(book< - qbooks)yield(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)
}
答案 0 :(得分:1)
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)
答案 1 :(得分:0)
看看这个:
即:db.run(TableQuery[UserTable].result)