Я пытаюсь вытащить следующий код из класса в трейт для повторного использования:
import org.slf4j.{LoggerFactory, Logger}
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
object UserProfileFixtures {
val logger: Logger = LoggerFactory.getLogger(UserProfileFixtures.getClass)
val table = UserProfileQueries.query
// todo: Create a trait for all this
def createSchema(db: Database) = {
logger.info("Creating schema for the UserProfiles table")
Await.result(db.run((table.schema).create), Duration.Inf)
logger.info("UserProfiles table schema created")
}
}
Проблема в том, что table
неявно преобразуется во что-то, что добавляет свойство schema
. Если я просто подниму и сдвину приведенное выше, неявное преобразование table
не произойдет, и компилятор не сможет найти свойство schema
.
Как я могу узнать, какой тип я должен дать table
в следующем трейте?
import org.slf4j.Logger
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
trait FixtureHelper {
val logger: Logger
val data: Seq
val table: TableQuery[_] // this type is wrong...
def createSchema(db: Database) = {
logger.info("Creating schema")
// compiler can't resolve `schema` in the line below
Await.result(db.run(table.schema.create), Duration.Inf)
logger.info("Schema created")
}
}
Я использую slick 3.0 BTW, но это не должно иметь значения. Я хочу знать, как узнать тип значения после его неявного преобразования.