是否可以使用 IN 使用 Quill 更新多行

Is it possible to update multiple rows with Quill using IN

有可能产生类似

的东西
UPDATE employees SET gender = 'Male' WHERE id IN ('asfd','bleh');

用羽毛笔?我没有在文档中找到示例,并且 batch update seems to be something else.

对我有用(试试 https://scastie.scala-lang.org/):

静态查询:

import io.getquill._

val ctx = new SqlMirrorContext(PostgresDialect, SnakeCase)

import ctx._

case class Product(name: String, price: Int)

def products(names: Seq[String], name: String) =
    ctx.run {
      ctx
        .query[Product]
        .filter(person => quote(liftQuery(names).contains(person.name)))
        .update(_.name -> lift(name))
}

val m = products(Seq("AA", "BB"), "EE")

println(m.string)

动态查询

import io.getquill._

val ctx = new SqlMirrorContext(PostgresDialect, SnakeCase)

import ctx._

case class Product(name: String, price: Int)

def products(names: Seq[String], name: String) =
    ctx.run {
      ctx
        .dynamicQuery[Product]
        .filter(person => quote(liftQuery(names).contains(person.name)))
        .update(setValue(_.name, name))
}

val m = products(Seq("AA", "BB"), "EE")

println(m.string)

输出:

UPDATE product SET name = ? WHERE name IN (?, ?)