typelevel / typelevel/doobie

case class default parameters

Open
#274 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
379
Avg merge
14m
Merged PRs (30d)
8

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the case class example in FooSpec.scala and inspect the shapeless dependency, especially the reported 2.3.0 support for default parameters. Use the AnalysisSpec example and the failure at DoobieEventComponentSpec.scala:34 as the starting points. Done means q1 typechecks without the too-few-columns error.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.