zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 346 forks source link

Type ascription to schemaMeta causes "Batch actions must be static quotations." #1308

Open Krever opened 5 years ago

Krever commented 5 years ago

Adding type annotation in

implicit val schema: ctx.SchemaMeta[Row] = schemaMeta[Row]("rows")

breaks batch queries but doesnt affect normal ones.

I'm, raising this mostly to help other people google the answer. It would be nice to fix it (either by a better error message, a warning message or changing the behavior) but I expect it's not so easy.

Version: 2.6.0 Module: core? Database: any

Actual behavior

Batch actions must be static quotations.

Steps to reproduce the behavior

https://scastie.scala-lang.org/VKzicxs6SKukBdlkXw6ZZg

Workaround

Remove type ascription

@getquill/maintainers

Tvaroh commented 5 years ago

Having similar issue with querySchema, which breaks batch inserts. Seems pretty major issue, no?

mdedetrich commented 5 years ago

@Krever I have tried removing the type ascription however this means the implicit value isn't even picked up. According to Intellij the implicit isn't even used and also judging by the compile output of the query it isn't even picked up.

mdedetrich commented 5 years ago

Actually ignore my above comment, Intellij was wrong and quill was actually picking it up

t3hnar commented 5 years ago

Hi, are there any plans on fixing this?

loicdescotte commented 5 months ago

It may be the same issue, I have an error trying to write generic insert code like

def store[A: SchemaMeta : Encoder](datas: List[A]): ZIO[Any, PostgresWriteError, Unit] = ZIO.attempt {
    val q = quote {
      liftQuery(datas).foreach(d => query[A].insertValue(d))
    }
    ctx.run(q)
  }.mapError(e => PostgresWriteError(e.getMessage)).unit

this example fails with a compile error : Batch actions must be static quotations. Found: 'q'