1

scalaquery-examples 项目中的FirstExample 提供了一个批量插入的示例,语法如下:

 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)
  )

鉴于对于此示例,函数定义为:如何在 InsertAll 方法中传递动态构造的元组列表:

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

1 回答 1

3

您可以将 List 转换为可变长度参数,如下所示:

insertAll(tuplesList.toSeq:_*)
于 2012-01-04T13:18:48.740 回答