Skip to content

Commit

Permalink
doobie: sql file repos should also return ConnectionIO, not Query0
Browse files Browse the repository at this point in the history
it's impossible to write mock repos for `Query0`
  • Loading branch information
oyvindberg committed May 16, 2023
1 parent 89f1a25 commit 9216466
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
package adventureworks
package person_detail

import doobie.util.query.Query0
import doobie.free.connection.ConnectionIO
import fs2.Stream

trait PersonDetailSqlRepo {
def apply(businessentityid: /* nullability unknown */ Option[Int]): Query0[PersonDetailSqlRow]
def apply(businessentityid: /* nullability unknown */ Option[Int]): Stream[ConnectionIO, PersonDetailSqlRow]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import adventureworks.public.Name
import doobie.Get
import doobie.Read
import doobie.enumerated.Nullability
import doobie.free.connection.ConnectionIO
import doobie.syntax.string.toSqlInterpolator
import doobie.util.query.Query0
import fs2.Stream
import java.sql.ResultSet

object PersonDetailSqlRepoImpl extends PersonDetailSqlRepo {
override def apply(businessentityid: /* nullability unknown */ Option[Int]): Query0[PersonDetailSqlRow] = {
override def apply(businessentityid: /* nullability unknown */ Option[Int]): Stream[ConnectionIO, PersonDetailSqlRow] = {
val sql =
sql"""SELECT s.businessentityid,
p.title,
Expand All @@ -34,7 +35,7 @@ object PersonDetailSqlRepoImpl extends PersonDetailSqlRepo {
JOIN person.address a ON a.addressid = bea.addressid
where s.businessentityid = $businessentityid
"""
sql.query[PersonDetailSqlRow]
sql.query[PersonDetailSqlRow].stream

}
implicit val read: Read[PersonDetailSqlRow] =
Expand Down
4 changes: 2 additions & 2 deletions typo/src/scala/typo/internal/codegen/DbLibDoobie.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object DbLibDoobie extends DbLib {
case Nil => sc.Code.Empty
case nonEmpty => nonEmpty.map { param => sc.Param(param.name, param.tpe, None).code }.mkCode(",\n")
}
code"def apply($params): ${Query0.of(sqlScript.RowName)}"
code"def apply($params): ${fs2Stream.of(ConnectionIO, sqlScript.RowName)}"
}

def matchId(id: IdComputed): sc.Code =
Expand Down Expand Up @@ -281,7 +281,7 @@ object DbLibDoobie extends DbLib {
}
code"""|val sql =
| ${SQL(renderedScript)}
|sql.query[${sqlScript.RowName}]
|sql.query[${sqlScript.RowName}].stream
|""".stripMargin
}

Expand Down

0 comments on commit 9216466

Please sign in to comment.