doobie icon indicating copy to clipboard operation
doobie copied to clipboard

case class default parameters

Open cranst0n opened this issue 8 years ago • 3 comments

Given:


// AnalysisSpec

case class Foo(bar: Long, baz: Int, shenanigans: Array[Byte] = Array[Byte]())
val q0 = sql"""select f.bar, f.baz, f.shenanigans from Foo f""".query[Foo]
val q1 = sql"""select f.bar, f.baz from Foo f""".query[Foo]

"Example" should {
  "have typechecked queries" in {
    checkOutput(q0)
    checkOutput(q1)
  }
}

q1 will not type check due to the default parameter for shenanigans:

[info] Example should
[info]   have typechecked queries
[info]     Query0[FooSpec.Foo] defined at FooSpec.scala:33
[info]       select f.bar, f.baz, f.shenanigans from Foo f
[info]       + SQL Compiles and Typechecks
[info]       + C01 bar         BIGINT        (BIGINT)     NOT NULL  →  Long
[info]       + C02 baz         INTEGER       (INT)        NOT NULL  →  Int
[info]       + C03 shenanigans LONGVARBINARY (MEDIUMBLOB) NOT NULL  →  Array[Byte]
[info]     Query0[FooSpec.Foo] defined at FooSpec.scala:34
[info]       select f.bar, f.baz from Foo f
[info]       + SQL Compiles and Typechecks
[info]       + C01 bar BIGINT  (BIGINT) NOT NULL  →  Long
[info]       + C02 baz INTEGER (INT)    NOT NULL  →  Int
[error]       x C03                                →  Array[Byte]
[error]        x Too few columns are selected, which will result in a runtime failure. Add a
[error]          column or remove mapped Array[Byte] from the result type. (DoobieEventComponentSpec.scala:34)

@milessabin reports that shapeless 2.3.0 supports default parameters so this will hopefully be solved when the dependency is updated.

cranst0n avatar Mar 01 '16 18:03 cranst0n

Hi, thanks. I'll take a look at this for the next version.

tpolecat avatar Mar 02 '16 12:03 tpolecat

In case if someone needs a temporary solution: https://gist.github.com/LMnet/2be88b61078a5cc1416312850093166c

LMnet avatar Nov 08 '19 05:11 LMnet

any update on this?

halfhp avatar Jun 13 '22 19:06 halfhp