zio / zio-protoquill

Quill for Scala 3
Apache License 2.0
198 stars 48 forks source link

Tuple swap fails at runtime #443

Closed Primetalk closed 2 months ago

Primetalk commented 2 months ago

Version: master as well as v4.8.3 Module: quill-sql Database: MirrorContext

Expected behavior

Tuple.swap should work at runtime:

type MyRow1 = (Int, String)

inline def myRow1Query = quote {
  querySchema[MyRow1]("my_table", t => t._1 -> "int_field", t => t._2 -> "string_field")
}

inline def g = quote {
  myRow1Query.map {
    case (i, s) => (s, i) // return another tuple with parts swapped
  }
}

val result = ctx.run(g)
require(result.extractor(Row(123, "St"), MirrorSession.default) == ("St", 123))

Actual behavior

It fails with

 java.lang.RuntimeException: Invalid column type. Expected 'class java.lang.String', but got '123'

Steps to reproduce the behavior

The issue can be reproduced using a mirror context:

https://scastie.scala-lang.org/53ULgsWkS3CgKlVwJ0TbxQ

@getquill/maintainers

Primetalk commented 2 months ago

Looks like I misinterpreted .extractor function. It only works as an extractor from query results, not as a full fledged query interpreter..