Hi guys, sorry for the super noob question but I could found info about how use autoinc with slick 1 but not with slick 2.1
I try this
class Buyers(tag: Tag) extends Table[(Option[Long], String, Int, String)](tag, "buyers") {
def id = column[Option[Long]]("id",O.PrimaryKey,O.AutoInc)
def name = column[String]("name")
def city = column[String]("city")
def * = (id.?, name, city)
}
based in the sample
case class User(id: Option[Int], first: String, last: String)
class Users(tag: Tag) extends Table[User](tag, "users") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def first = column[String]("first")
def last = column[String]("last")
def * = (id.?, first, last) <> (User.tupled, User.unapply)
}
but I get error
<console>:19: error: No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
Required level: scala.slick.lifted.FlatShapeLevel
Source type: (scala.slick.lifted.Column[Option[Long]], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])
Unpacked type: (Option[Long], String, Int, String)
Packed type: Any
def * = (id, name, city)
I also try
case class Supplier(id: Int, name: String, street: String)
class Suppliers(tag: Tag) extends Table[Supplier](tag, "SUPPLIERS") {
def id = column[Int]("SUP_ID", O.PrimaryKey, O.AutoInc)
def name = column[String]("SUP_NAME")
def street = column[String]("STREET")
def * = (id, name, street) <> (Supplier.tupled, Supplier.unapply)
}
val suppliers = TableQuery[Suppliers]
suppliers.insert(mySupplier)
but is not clear how add new suppliers in this way...
suppliers.insert(Supplier(???? , "john smith","212")) if I supply an Int as id I suppose than the autoinc is not applied, don't must be the id an option type??...