Compiled Querys in Slick

我怕爱的太早我们不能终老 提交于 2019-12-12 17:23:18

问题


I need to compile a query in Slick with Play and PostgreSQL

val bioMaterialTypes: TableQuery[Tables.BioMaterialType] = Tables.BioMaterialType

def getAllBmts() = for{ bmt <- bioMaterialTypes } yield bmt

val queryCompiled = Compiled(getAllBmts _)

but in Scala IDE I get this error in the Apply of Compiled

Multiple markers at this line
- Computation of type () => scala.slick.lifted.Query[models.Tables.BioMaterialType,models.Tables.BioMaterialTypeRow,Seq] 
 cannot be compiled (as type C)
- not enough arguments for method apply: (implicit compilable: scala.slick.lifted.Compilable[() => 
 scala.slick.lifted.Query[models.Tables.BioMaterialType,models.Tables.BioMaterialTypeRow,Seq],C], implicit driver: 
 scala.slick.profile.BasicProfile)C in object Compiled. Unspecified value parameters compilable, driver.

This are my imports:

import scala.concurrent.Future
import scala.slick.jdbc.StaticQuery.staticQueryToInvoker
import scala.slick.lifted.Compiled
import scala.slick.driver.PostgresDriver
import javax.inject.Inject
import javax.inject.Singleton
import models.BioMaterialType
import models.Tables
import play.api.Application
import play.api.db.slick.Config.driver.simple.TableQuery
import play.api.db.slick.Config.driver.simple.columnExtensionMethods
import play.api.db.slick.Config.driver.simple.longColumnType
import play.api.db.slick.Config.driver.simple.queryToAppliedQueryInvoker
import play.api.db.slick.Config.driver.simple.queryToInsertInvoker
import play.api.db.slick.Config.driver.simple.stringColumnExtensionMethods
import play.api.db.slick.Config.driver.simple.stringColumnType
import play.api.db.slick.Config.driver.simple.valueToConstColumn
import play.api.db.slick.DB
import play.api.db.slick.DBAction

回答1:


You can simply do

val queryCompiled = Compiled(bioMaterialTypes)


来源:https://stackoverflow.com/questions/27234554/compiled-querys-in-slick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!