f7h f7h - 2 months ago 18
Scala Question

Can't get the "*" method of a slick table right

I am a new Slick user and I have a problem with the "*" method of a table. I can't get it right. Here the code :
package models

import slick.lifted.{ProvenShape, ForeignKeyQuery}
import slick.driver.PostgresDriver.api._

import scala.concurrent.ExecutionContext.Implicits.global

case class Coordonnee (id:Option[Long],
email:String,email_publique:Boolean,email_publique_assoc:Boolean,
rue:String,rue_publique:Boolean,rue_publique_assoc:Boolean,
codepostal:String,codepostal_publique:Boolean,codepostal_publique_assoc:Boolean,
ville:String,ville_publique:Boolean,ville_publique_assoc:Boolean,
phone:String,phone_publique:Boolean,phone_publique_assoc:Boolean,
phonemaison:String,phonemaison_publique:Boolean,phonemaison_publique_assoc:Boolean
)
class Coordonnees(tag:Tag) extends extends Table[Coordonnee](tag, "COORDONNEES"){

def id = column[Long]("COORDONNEES_ID", O.AutoInc, O.PrimaryKey)

def email = column[String]("EMAIL")
def email_publique = column[Boolean]("EMAIL_PUBLIQUE")
def email_publique_assoc = column[Boolean]("EMAIL_PUBLIQUE_ASSOC")

def rue = column[String]("RUE")
def rue_publique = column[Boolean]("RUE_PUBLIQUE")
def rue_publique_assoc = column[Boolean]("RUE_PUBLIQUE_ASSOC")

def codepostal = column[String]("CODEPOSTAL")
def codepostal_publique = column[Boolean]("CODEPOSTAL_PUBLIQUE")
def codepostal_publique_assoc = column[Boolean]("CODEPOSTAL_PUBLIQUE_ASSOC")

def ville = column[String]("VILLE")
def ville_publique = column[Boolean]("VILLE_PUBLIQUE")
def ville_publique_assoc = column[Boolean]("VILLE_PUBLIQUE_ASSOC")

def phone = column[String]("PHONE")
def phone_publique = column[Boolean]("PHONE_PUBLIQUE")
def phone_publique_assoc = column[Boolean]("PHONE_PUBLIQUE_ASSOC")

def phonemaison = column[String]("PHONEMAISON")
def phonemaison_publique = column[Boolean]("PHONEMAISON_PUBLIQUE")
def phonemaison_publique_assoc = column[Boolean]("PHONEMAISON_PUBLIQUE_ASSOC")

def * : ProvenShape[(Long,
String,Boolean,Boolean,
String, Boolean,Boolean,
String,Boolean,Boolean,
String,Boolean,Boolean,
String,Boolean,Boolean,
String,Boolean,Boolean)]=
(id,
email, email_publique, email_publique_assoc,
rue,rue_publique,rue_publique_assoc,
codepostal,codepostal_publique, codepostal_publique_assoc,
ville,ville_publique,ville_publique_assoc,
phone,phone_publique,phone_publique_assoc,
phonemaison,phonemaison_publique,phonemaison_publique_assoc
) <> (Coordonnee.tupled, Coordonnee.unapply)
}


the error in the Idea IDE is :


Error:Play 2 Compiler:
Required level: slick.lifted.FlatShapeLevel
Source type: (slick.lifted.Rep[Long], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean], slick.lifted.Rep[String], slick.lifted.Rep[Boolean], slick.lifted.Rep[Boolean])
Unpacked type: (Option[Long], String, Boolean, Boolean, String, Boolean, Boolean, String, Boolean, Boolean, String, Boolean, Boolean, String, Boolean, Boolean, String, Boolean, Boolean)


I am using Slick v3.1.1. If I delete the


<> (Coordonnee.tupled, Coordonnee.unapply)


it works but I need it.

first edit : modification of "extends Table[..." as suggested by pamu

Answer

Instead of Table[(....)] use Table[Coordonnee]

Instead of this code

 class Coordonnees(tag:Tag) extends Table[(Long,
  String,Boolean,Boolean,
  String, Boolean,Boolean,
  String,Boolean,Boolean,
  String,Boolean,Boolean,
  String,Boolean,Boolean,
  String,Boolean,Boolean

  )](tag, "COORDONNEES") { //.... }

Use this code

 class Coordonnees(tag:Tag) extends Table[Coordonnee] { //... }

Complete code that compiles

import slick.lifted.{ProvenShape, ForeignKeyQuery}
import slick.driver.PostgresDriver.api._

import scala.concurrent.ExecutionContext.Implicits.global

case class Coordonnee(id: Option[Long],
                      email: String, email_publique: Boolean, email_publique_assoc: Boolean,
                      rue: String, rue_publique: Boolean, rue_publique_assoc: Boolean,
                      codepostal: String, codepostal_publique: Boolean, codepostal_publique_assoc: Boolean,
                      ville: String, ville_publique: Boolean, ville_publique_assoc: Boolean,
                      phone: String, phone_publique: Boolean, phone_publique_assoc: Boolean,
                      phonemaison: String, phonemaison_publique: Boolean, phonemaison_publique_assoc: Boolean
                     )

class Coordonnees(tag: Tag) extends Table[Coordonnee](tag, "COORDONNEES") {

  def id = column[Long]("COORDONNEES_ID", O.AutoInc, O.PrimaryKey)

  def email = column[String]("EMAIL")

  def email_publique = column[Boolean]("EMAIL_PUBLIQUE")

  def email_publique_assoc = column[Boolean]("EMAIL_PUBLIQUE_ASSOC")

  def rue = column[String]("RUE")

  def rue_publique = column[Boolean]("RUE_PUBLIQUE")

  def rue_publique_assoc = column[Boolean]("RUE_PUBLIQUE_ASSOC")

  def codepostal = column[String]("CODEPOSTAL")

  def codepostal_publique = column[Boolean]("CODEPOSTAL_PUBLIQUE")

  def codepostal_publique_assoc = column[Boolean]("CODEPOSTAL_PUBLIQUE_ASSOC")

  def ville = column[String]("VILLE")

  def ville_publique = column[Boolean]("VILLE_PUBLIQUE")

  def ville_publique_assoc = column[Boolean]("VILLE_PUBLIQUE_ASSOC")

  def phone = column[String]("PHONE")

  def phone_publique = column[Boolean]("PHONE_PUBLIQUE")

  def phone_publique_assoc = column[Boolean]("PHONE_PUBLIQUE_ASSOC")

  def phonemaison = column[String]("PHONEMAISON")

  def phonemaison_publique = column[Boolean]("PHONEMAISON_PUBLIQUE")

  def phonemaison_publique_assoc = column[Boolean]("PHONEMAISON_PUBLIQUE_ASSOC")

  def *
  = (id.?,
    email, email_publique, email_publique_assoc,
    rue, rue_publique, rue_publique_assoc,
    codepostal, codepostal_publique, codepostal_publique_assoc,
    ville, ville_publique, ville_publique_assoc,
    phone, phone_publique, phone_publique_assoc,
    phonemaison, phonemaison_publique, phonemaison_publique_assoc
    ) <> (Coordonnee.tupled, Coordonnee.unapply)
}

notice in the * method id replaced with id.?

Comments