Search code examples
scaladslscalaquery

scalaquery : Dynamic BatchInsert


The FirstExample in scalaquery-examples project provides an example of batch insert with the following Syntax:

 Coffees.insertAll(
    ("Colombian", 101, 7.99, 0, 0),
    ("French_Roast",49, 8.99, 0, 0),
    ("Espresso",150, 9.99, 0, 0),
    ("Colombian_Decaf",101, 8.99, 0, 0),
    ("French_Roast_Decaf", 49, 9.99, 0, 0)
  )

How is it possible to pass a dynamically constructed List of tuples in the InsertAll method given that for this example the function definition is:

def insertAll(values: (String, Int, Double, Int, Int)*)(implicit session: org.scalaquery.session.Session): Option[Int]

Solution

  • You can transform your List to variable-length arguments like this:

    insertAll(tuplesList.toSeq:_*)