Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with nested query error #2666

Open
Grednoud opened this issue Dec 3, 2022 · 1 comment
Open

Update with nested query error #2666

Grednoud opened this issue Dec 3, 2022 · 1 comment

Comments

@Grednoud
Copy link

Grednoud commented Dec 3, 2022

Tell me how can I write a query to update a field with a nested query using quill?

Version: 3.19.0
Module: quill-jdbc-zio
Database: postgresql

Expected behavio

The query that should be the result: UPDATE table1 SET field = 'foo' WHERE id IN (SELECT id FROM table2 WHERE field IN (value1, value2))

Actual behavior

The compiler tells me that I will get the right request, but I keep getting an error.
Tell me how can I write a query to update a field with a nested query using quill?

Steps to reproduce the behavior

In quill it loks like:

val table1 = quote(querySchema[Table1]("table1"))
val table2 = quote(querySchema[Table2]("table2"))

val params = List("param1", "param2")

quote{
  table1
    .filter(t => table2.filter(t2 => liftQuery(params).contains(t2.field))
      .map(_.id)
      .contains(t.id)
    )
    .update(_.field -> lift("foo"))
}

Workaround

Not found

@getquill/maintainers

@Grednoud
Copy link
Author

Found a solution for such a request.

quote{
  table1
    .filter(t => table2.filter(t2 => infix"${t2.field} IN (${lift(params.mkString(","))})".as[Boolean])
      .map(_.id)
      .contains(t.id)
    )
    .update(_.field -> lift("foo"))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant