33
votes

In slick table there is a tag parameter:

class Companies(tag: Tag) extends Table[Company](tag,"COMPANY") {...}

What is it used for, and is there any way not to write it with each table class definition?

2
thwiegan: I saw this question, but it doesn't answer what do I need the tag for as a Slick library user. I understand they do use it internally in Slick, but looks like there is no use of it for the user outside Slick library. If so then why do I need that boilerplate in my code?Taras Bilinsky
I also do not see any way not to use type the tag boilerplate every time I define a table class, neither subclassing nor any kind of wrapping nor even def macro would help. I thought maybe someone happens to know the way...Taras Bilinsky
I've tried to spend some time looking into sources but it's quite hard to parse without big picture view on the Slick internal architecture which is not described anywhere. The tagging itself is not documented at all. Would be great if Slick team could publish some doc with internal architecture description, at least high-level. That would help such library users as we are to better use it.Alexander Arendar
After digging in version 3.2.1 sources I came to conclusion, that it is an leaked internal abstraction (no surprise here): Slick builds queries using some internal AST. That AST has Nodes, and Tags are their metadata, that allows AST to distinguish, which of them are e.g. straight table queries and which work on some projections/subqueries/wild stuff. But such metadata, for some reason, was not prevented from being exposed to everyone writing Slick, though it should have been.Mateusz Kubuszok

2 Answers

1
votes

The best answer I've seen is: https://stackoverflow.com/a/27783730/154248

What's it used for: imagine you needed to join a table on itself. That tag is a way to distinguish between the tables taking part in a query.

0
votes

The Tag provides the AbstractTable definition of the type, and is passed by Slicks internals.