3

Could you please demonstrate how to use Slick's StaticQuery.update with parameters ? Documentation shows only parameterless call. I didn't find example in unit-tests either.

expert
  • 29,290
  • 30
  • 110
  • 214
  • I can give you an example using plain sql if you want. Our whole data layer is built on slick plain sql, so I have plenty examples of updates. Just not sure you wanted to see it as the plan sql flavor. – cmbaxter May 28 '13 at 00:57

1 Answers1

8

Here's a simple example, showing an update with two input params. Note that this code assumes that an implicit Session is in scope:

import scala.slick.jdbc.{StaticQuery => Q}
val updateEmailSql = Q.update[(String,Long)]("update User set email = ? where id = ?")
val rowsUpdated = updateEmailSql(("foo@test.com", 1L)).first()

The rowsUpdated val here will be an Int representing the number of rows that were affected by this update statement.

cmbaxter
  • 35,283
  • 4
  • 86
  • 95
  • Thank you!! Could you please also suggest how to solve this problem with Slick ? http://stackoverflow.com/q/16756086/226895 – expert May 28 '13 at 06:16
  • What about a case with using the same parameter multiple times in the query? – sedovav Jun 02 '15 at 22:45