1

Assume we have a table

class Entry(tag :Tag) extends Table[(String, Long)](tag, "entries") {
    def name = column[String]("name")
    def value = column[Long]("value")
    def * = (name, value)
}
val Entries = new TableQuery(new Entry(_))

and a query of type Query[(Column[String], Column[Long]), (String, Long)]. Can I somehow convert it to Query[Entry, (String, Long)]? This would be very useful in case of grouping queries such as Entries.groupBy(_.name).map(g=>(g._1, g._2.map(_.value).avg))

Turin
  • 2,208
  • 15
  • 23

1 Answers1

0

try this :

case  class Entry(name: String,value: Long)

class Entries(tag :Tag) extends Table[Entry](tag, "entries") {
   def name = column[String]("name")
   def value = column[Long]("value")
   def * = (name, value) <>(Entry.tupled, Entry.unapply )
 }
val Entries = TableQuery[Entries]
Sky
  • 2,509
  • 1
  • 19
  • 28
  • The actual TableElementType has nothing to do with it. The result of the above groupBy is still the same. – Turin Mar 21 '14 at 21:32