Where is the .ddl method defined in Slick's Scaladoc

123 Views Asked by At

I have figured out for creating a Postgres table, I need to have this import line import slick.driver.PostgresDriver.simple._

However, when I go an look at the Scaladoc for SimpleQL, I cannot find a method for ddl, am I looking in the wrong place? This is really an exercise for me navigating Scaladocs. I can see that TableQuery is aliased, but I do not see any extra methods added to it.

TLDR: Where is the ddl method defined at in Slick 2.1.0's scala docs?

1

There are 1 best solutions below

0
On

The definition of method ddl is included in the description of classes TableQueryExtensionMethods and Sequence. It can be found, for example, via Scaladoc's index.

Why does that make sense?

Consider the following code which got myself confused for some time:

import scala.slick.driver.H2Driver.simple._
// [..]
val dict = TableQuery[Dict]
// [..]
// Create the dictionary table and insert some data
dict.ddl.create

First, note that the import in given example is very similar to the one in the question. I just use a different database.

Method ddl is applied to a value of type TableQuery[Dict] although class TableQuery obviously does not contain this method.

Instead, it was shown that class TableQueryExtensionMethods contains this method.

The implementation of class TableQueryExtensionMethods shows that Slick's developers make use of an implicit Conversion from TableQuery to TableQueryExtensionMethods:

 implicit def tableQueryToTableQueryExtensionMethods [T <: Table[_], U](q: Query[T, U, Seq] with TableQuery[T]) 
    = new TableQueryExtensionMethods[T, U](q)

This allows the execution of line

dict.ddl.create

From the example above.