1

I know I can define a table in Slick as follows:

class MyTable(tag: Tag)

but what is it exactly?

I read the docs and it says:

A Tag marks a specific row represented by an AbstractTable instance.

it does not help me,

  1. what does it means a specific row?
  2. how does it represents it?
  3. why do I need to define it in my ctor?
  4. why is it called a Tag what is it tagging?
  5. I need to write this Tag when I create a Table class, but I want to understand why I write this code, not just follow slick which tells me this is how you define a table.
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Jas
  • 14,493
  • 27
  • 97
  • 148
  • 1
    Can the [source](https://github.com/slick/slick/blob/master/src/main/scala/scala/slick/lifted/AbstractTable.scala) help you? – Steven Dobay Jan 05 '15 at 11:31
  • i looked at this source it keeps saying: "A Tag marks a specific row " why? "Return a new instance of the AbstractTable carrying this Tag" why? "def taggedAs(path: Node): AbstractTable[_]" why tag it? "A Tag for table instances that represent a Node" ok then what is a tag? "abstract class RefTag(val path: Node) extends Tag" so there is a ref tag what is it? "trait BaseTag extends Tag" another tag what is it? "sealed trait Tag" why do i need it? – Jas Jan 05 '15 at 11:54
  • 1
    If you understand the word "Tag" then it isn't hard to understand what is tagging(or jump to [Google translator](https://translate.google.en) if you a foreigner). When you create a table, you give it a tag because every instances of AbstractTable requires it. When slick generates SQL those tags can give a new path in the nodes of AST as i think. Tag can be mean as a tablemodel's id. – Steven Dobay Jan 05 '15 at 12:21

1 Answers1

5

You can think about Tag like a SQL alias. It distinguishes different instances of the same table within a query.

cvogt
  • 11,260
  • 30
  • 46
  • 2
    thanks, this adds a lot to my understanding, but why do I need to be aware of this? if i'm not updating at all this tag param `class Coffees(tag: Tag) extends Table[(String, Double)](tag, "COFFEES") {` then why do I need to have this in my slick client code? all i'm doing is passing it as is to parent why do i need to see it in my code? why is it not only internal to slick code? – Jas Jan 05 '15 at 17:26
  • 1
    When you create a TableQuery from a Table subclass, Slick generates a tag and passes it in. Not sure right now if we could have done it differently, but it seemed necessary at the time. – cvogt Jan 08 '15 at 21:59
  • 1
    @szeiger may have some more insight on the mailing list, he added it back then – cvogt Jan 08 '15 at 22:00