Search code examples
scalaplayframeworkslicktypesafe

In Slick 3.0, why could `result` method be applied to a `Query` object?


I'm using Slick 3.0: https://github.com/slick/slick/tree/3.0.0

The example codes looks like this:

class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {
  def name = column[String]("COF_NAME", O.PrimaryKey)
  def price = column[Double]("PRICE")
  def * = (name, price)
}
val coffees = TableQuery[Coffees]
val coffeeNames: Future[Seq[Double]] = db.run(
  coffees.map(_.price).result
)

I think the result method in coffees.map(_.price).result is described here:

http://www.scala-lang.org/api/2.11.5/index.html#scala.collection.mutable.Builder@result():To

which is a method of Builder class.

However, coffees.map(_.price) is a Query class instead of Builder class, and Query class seems not a subclass of Builder class. Moreover, there seems no implicit conversion from Query class to Builder class. And Query class doesn't have a method called result.

So how does the result be applied to the Query object. Does anyone have ideas about this?


Solution

  • The result method is not from Builder class. It is defined in QueryActionExtensionMethodsImpl class in JdbcActionComponent.scala file.