Skip to content

Commit

Permalink
Add {Write.Read}.generic back to help migrate from earlier versions
Browse files Browse the repository at this point in the history
These methods are used by users to derive instances explicitly in
previous versions. The implicit keywords are removed so they don't
affect implicit search
  • Loading branch information
jatcwang committed Sep 17, 2024
1 parent 03f944d commit db602b5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package doobie.util
import shapeless._
import shapeless.ops.hlist.IsHCons

trait GetPlatform {
trait MkGetPlatform {
import doobie.util.compat.=:=

/** @group Instances */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package doobie.util
import shapeless._
import shapeless.ops.hlist.IsHCons

trait PutPlatform {
trait MkPutPlatform {
import doobie.util.compat.=:=

/** @group Instances */
Expand Down
3 changes: 3 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/ReadPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ trait ReadPlatform {
MkRead.ogeneric[A, Repr]
}

@deprecated("Use Read.derived instead to derive instances explicitly", "1.0.0-RC6")
def generic[T, Repr](implicit gen: Generic.Aux[T, Repr], G: Lazy[MkRead[Repr]]): MkRead[T] =
MkRead.generic[T, Repr]
}
4 changes: 4 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/WritePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ trait WritePlatform {
val _ = isTuple
MkWrite.ogeneric[A, Repr]
}

@deprecated("Use Write.derived instead to derive instances explicitly", "1.0.0-RC6")
def generic[T, Repr](implicit gen: Generic.Aux[T, Repr], A: Lazy[MkWrite[Repr]]): MkWrite[T] =
MkWrite.generic[T, Repr]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package doobie.util

import scala.deriving.Mirror

trait GetPlatform:
trait MkGetPlatform:

// Get is available for single-element products.
given x[P <: Product, A](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package doobie.util

import scala.deriving.Mirror

trait PutPlatform:
trait MkPutPlatform:

// Put is available for single-element products.
given [P <: Product, A](
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/main/scala/doobie/util/get.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ sealed abstract class MkGet[A](
override val vendorTypeNames: List[String],
override val get: Coyoneda[(ResultSet, Int) => *, A]
) extends Get[A](typeStack, jdbcSources, jdbcSourceSecondary, vendorTypeNames, get)
object MkGet extends GetPlatform {

object MkGet extends MkGetPlatform {

def lift[A](g: Get[A]): MkGet[A] =
new MkGet[A](
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/main/scala/doobie/util/put.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ sealed abstract class MkPut[A](
override val put: ContravariantCoyoneda[(PreparedStatement, Int, *) => Unit, A],
override val update: ContravariantCoyoneda[(ResultSet, Int, *) => Unit, A]
) extends Put[A](typeStack, jdbcTargets, vendorTypeNames, put, update)
object MkPut extends PutPlatform {

object MkPut extends MkPutPlatform {

def lift[A](g: Put[A]): MkPut[A] =
new MkPut[A](
Expand Down
15 changes: 5 additions & 10 deletions modules/core/src/test/scala-2/doobie/util/PutSuitePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,26 @@

package doobie.util
import doobie.testutils.{VoidExtensions, assertContains}
import doobie.testutils.TestClasses.CCAnyVal

object PutSuitePlatform {
final case class Y(x: String) extends AnyVal
final case class P(x: Int) extends AnyVal
}
object PutSuitePlatform {}

trait PutSuitePlatform { self: munit.FunSuite =>
import PutSuitePlatform._

test("Put can be auto derived for unary products (AnyVal)") {
import doobie.generic.auto._

Put[Y].void
Put[P].void
Put[CCAnyVal].void
}

test("Put can be explicitly derived for unary products (AnyVal)") {
Put.derived[Y].void
Put.derived[P].void
Put.derived[CCAnyVal].void
}

test("Put should not be derived for non-unary products") {
import doobie.generic.auto._
import doobie.testutils.TestClasses.{CCIntString, PlainObj}

println(compileErrors("Put[CCIntString]"))
assertContains(compileErrors("Put[CCIntString]"), "implicit value")
assertContains(compileErrors("Put[(Int, Int)]"), "implicit value")
assertContains(compileErrors("Put[PlainObj.type]"), "implicit value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ object TestClasses {

case class CCIntString(i: Int, s: String)

case class CCAnyVal(s: String) extends AnyVal

object PlainObj
}

0 comments on commit db602b5

Please sign in to comment.