JulienD
JulienD

Reputation: 7293

Slick: get table name

With a table definition like this one:

class Test(_tableTag: Tag) extends Table[TestRow](_tableTag, "test") { ... }

how can I get back the table name (Tag "test") from an instance of Test?

The thing is I can perfectly execute some queries like db run TableQuery[Test].result, but to write raw sql, I need the table name.

Upvotes: 1

Views: 1371

Answers (1)

insan-e
insan-e

Reputation: 3921

If you look at Slick's TableQuery ScalaDoc there is a method called baseTableRow which says:

def baseTableRow: E

Get the "raw" table row that represents the table itself, as opposed to a Path for a variable of the table's type. This method should generally not be called from user code.

So you go to E <: AbstractTable's "definition" (AbstractTable) Scaladoc and find what you need, namely val tableName: String. The trick here is to know where to look (possible implicit conversions and other stuff...), that is, how to navigate the Scala(Doc) rabbithole. xD

Upvotes: 6

Related Questions