scalaquery:动态批量插入

发布于 2024-12-24 16:40:34 字数 575 浏览 6 评论 0原文

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]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-12-31 16:40:34

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

insertAll(tuplesList.toSeq:_*)

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

insertAll(tuplesList.toSeq:_*)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文