1
votes

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.

2
I think u missed created_at in ur insert val insert = Users.map(u => (u.first,u.last,u.email,u.created_at)) += (Some("Bob"), Some("Smith"), Some("[email protected]"),"{DateTime}") - aravindKrishna
Could you show us your table definition, so we can reproduce your error? - Paweł Jurczenko
@aravindKrishna created_at is 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 .map rather than a += User(...) - Arne Claassen

2 Answers

1
votes

The error is actually a warning. The project was based on an activator template which predefined a number of compiler options including:

"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xlint", // Enable recommended additional warnings.
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver.

While removal of -Ywarn-adapted-args ought to have solved it, it appears the warning gets emitted under 2.11 because of -Xlint regardless

There is a related ticked on the compiler marked as won't fix: "unit insertion deprecation seems unavoidable in standard slick code

That means that at this time you have to turn off either -Xlint or -Xfatal-warnings to make this code pass.

0
votes

In your user entity define like below mentioned.

def creation_at = column[Timestamp]("creation_at",SqlType("timestamp not null default 0")),

if u insert none at creation_at column , on table written as 0.