Given:
case class User(id: Long,
first: Option[String],
last: Option[String],
email: Option[String],
verified_at: Option[DateTime],
created_at: DateTime)
class Users(tag: Tag) extends Table[User](tag, "user") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[Option[String]]("first_name")
def lastName = column[Option[String]]("last_name")
def email = column[Option[String]]("email")
def verifiedAt = column[Option[DateTime]]("verified_at")
def createdAt = column[DateTime]("created_at")
def * = (id, firstName, lastName, email, verifiedAt, createdAt) <>(User.tupled, User.unapply)
}
val userQuery = TableQuery[Users]
where created_at is a mysql TIMESTAMP (i.e. it self-populates if not specified in the insert sql statement), I want to create an insert that omits verified_at and created_at. From the Slick 3.0.0 docs I gather that this should do the trick:
val insert = userQuery.map(u => (u.first,u.last,u.email))
+= (Some("Bob"), Some("Smith"), Some("[email protected]"))
IntelliJ is happy with this code and if I do a insertStatement on the map I get the expected insert statement:
insert into `user` (`first_name`,`last_name`,`email`) values (?,?,?)
But on compile I get:
Error:(30, -1) Play 2 Compiler:
C:\proj\test\models\DBTableDefinitionsSpec.scala:30: Adapting argument list by creating a 3-tuple: this may not be what you want.
signature: SimpleInsertActionComposer.+=(value: U): JdbcActionComponent.this.DriverAction[SimpleInsertActionComposer.this.SingleInsertResult,slick.dbio.NoStream,slick.dbio.Effect.Write]
given arguments: Some("Bob"), Some("Smith"), Some("[email protected]")
Mind you this is just the statement preparation, it's not even related to the exectution. This is also already a reduced version -- I tried that same with the additional returning userQuery.map(_.id), which had the same error, so it doesn't seem related to the primary key.
Update: This turns out it was a warning turned error. I've left an answer below in case someone else hits this issue.
created_atis omitted on purpose, since I want the SQL to omit it, so that that mysql sets the timestamp. Which is why I'm using the.maprather than a+= User(...)- Arne Claassen