Skip to content

Commit

Permalink
Add test for issue typelevel#2144
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lebl-adastra committed Jan 29, 2025
1 parent e0a3105 commit 314742a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/core/src/test/scala/doobie/util/ReadSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
assertEquals(o2, List(None))
}

test("Read should read correct columns for instances with Option (None) with left join between two tables") {
import doobie.implicits.*

case class Foo(foo_key: Int, b: String)
case class Bar(bar_key: Int, d: Option[String])

val result: List[(Foo, Option[Bar])] = (for {
_ <- sql"drop table if exists foo".update.run
_ <- sql"drop table if exists bar".update.run
_ <- sql"create table foo(foo_key int, foo_value varchar not null)".update.run
_ <- sql"create table bar(bar_key int, foo_key int, bar_value varchar)".update.run

_ <- sql"insert into foo values (1, 'a'), (2, 'b'), (3, 'c')".update.run
_ <- sql"insert into bar values (1, 1, 'c'), (2, 2, null)".update.run

q <- sql"select f.foo_key, f.foo_value, b.bar_key, b.bar_value from foo f left join bar b on f.foo_key = b.foo_key".query[(Foo, Option[Bar])].to[List]
} yield q)
.transact(xa)
.unsafeRunSync()

assertEquals(result, List(
(Foo(1, "a"), Some(Bar(1, Some("c")))),
(Foo(2, "b"), Some(Bar(2, None))),
(Foo(3, "c"), None)
))
}

test("Read should read correct columns for instances with Option (Some)") {
import doobie.implicits.*

Expand Down

0 comments on commit 314742a

Please sign in to comment.