I wrote this very simple code which I saw in many places on the internet
import scala.slick.driver.H2Driver.simple._
import scala.concurrent.ExecutionContext.Implicits.global
import slick.jdbc.meta._
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.concurrent.duration._
object Helper {
def printTableNames() : Unit = {
val db = Database.forConfig("test1")
db.withSession {implicit session =>
val x = Await.result(MTable.getTables().list(), Duration.Inf).toList
x.foreach(println)
}
}
}
But this gives me a cryptic error at runtime
[error] /Users/abhi/ScalaProjects/SlickTest/src/test/scala/HelloSpec.scala:13: overloaded method value getTables with alternatives:
[error] => slick.profile.BasicStreamingAction[Vector[slick.jdbc.meta.MTable],slick.jdbc.meta.MTable,slick.dbio.Effect.Read] <and>
[error] (namePattern: String)slick.profile.BasicStreamingAction[Vector[slick.jdbc.meta.MTable],slick.jdbc.meta.MTable,slick.dbio.Effect.Read] <and>
[error] (cat: Option[String],schemaPattern: Option[String],namePattern: Option[String],types: Option[Seq[String]])slick.profile.BasicStreamingAction[Vector[slick.jdbc.meta.MTable],slick.jdbc.meta.MTable,slick.dbio.Effect.Read]
[error] cannot be applied to ()
[error] val x = Await.result(MTable.getTables().list(), Duration.Inf).toList
[error] ^
[error] one error found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 1 s, completed Jun 27, 2015 12:34:03 AM
Looks like there are three
getTables
methods all of which do not matchgetTables()
. Probably you're trying thegetTables
one (without the parenthesis)?With that, you'd then call just
list
(notlist()
). Slick definition for list:shows how there's no non-implicit parameter list. Therefore you want
list
rather thanlist()
.BUT... I see that the returned object is a stream, implying that
getTables
returns a stream (db.stream
rather thandb.run
). If you want the list, rather than a stream, cut out this unnecessary step and usedb.run
instead.Putting all that together, this should work, assuming you want to use the stream (given what I know so far):
(PS, it'd help if you mention the version of Slick you were using. Slick 3 very different to older versions.)