Skip to content

Commit ac95bd6

Browse files
authored
Merge pull request #2232 from satorg/get-put-final
Rid of anonymous `Get`s and `Put`s
2 parents 4829ecc + 640a9dd commit ac95bd6

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

modules/core/src/main/scala/doobie/util/get.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import doobie.util.meta.Meta
2424
* If non-empty, the column/parameter type reported by the database will be checked to match this list during
2525
* typechecking against the database.
2626
*/
27-
sealed abstract class Get[A](
27+
final class Get[A] private (
2828
val typeStack: NonEmptyList[Option[String]],
2929
val jdbcSources: NonEmptyList[JdbcType],
3030
val jdbcSourceSecondary: List[JdbcType],
@@ -66,7 +66,7 @@ sealed abstract class Get[A](
6666
jdbcSourceSecondary = jdbcSourceSecondary,
6767
vendorTypeNames = vendorTypeNames,
6868
get = get.map(f)
69-
) {}
69+
)
7070

7171
/** Equivalent to `tmap`, but allows the conversion to fail with an error message.
7272
*/
@@ -99,7 +99,7 @@ object Get extends GetInstances with GetPlatform {
9999
jdbcSourceSecondary = jdbcSourceSecondary,
100100
vendorTypeNames = checkedVendorType.toList,
101101
get = get
102-
) {}
102+
)
103103

104104
def many[A](
105105
jdbcSources: NonEmptyList[JdbcType],
@@ -116,7 +116,6 @@ object Get extends GetInstances with GetPlatform {
116116
checkedVendorType: Option[String]
117117
): Get[A] =
118118
many(NonEmptyList.of(jdbcSources), jdbcSourceSecondary, get, checkedVendorType)
119-
120119
}
121120

122121
/** Get instance for an advanced JDBC type. */
@@ -133,7 +132,7 @@ object Get extends GetInstances with GetPlatform {
133132
jdbcSourceSecondary = Nil,
134133
vendorTypeNames = vendorTypeNames.toList,
135134
get = get
136-
) {}
135+
)
137136

138137
def many[A](
139138
jdbcSources: NonEmptyList[JdbcType],

modules/core/src/main/scala/doobie/util/put.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.reflect.ClassTag
2323
* If non-empty, the column/parameter type reported by the database will be checked to match this list during
2424
* typechecking against the database.
2525
*/
26-
sealed abstract class Put[A](
26+
final class Put[A] private (
2727
val typeStack: NonEmptyList[Option[String]],
2828
val jdbcTargets: NonEmptyList[JdbcType],
2929
val vendorTypeNames: List[String],
@@ -53,7 +53,7 @@ sealed abstract class Put[A](
5353
vendorTypeNames = vendorTypeNames,
5454
put = put.contramap(f),
5555
update = update.contramap(f)
56-
) {}
56+
)
5757

5858
def unsafeSetNonNullable(ps: PreparedStatement, n: Int, a: A): Unit =
5959
if (a == null) sys.error(s"Expected non-nullable param at $n. Use Option to describe nullable values.")
@@ -100,7 +100,7 @@ object Put extends PutInstances {
100100
vendorTypeNames = checkedVendorType.toList,
101101
put = put,
102102
update = update
103-
) {}
103+
)
104104

105105
def many[A](
106106
jdbcTargets: NonEmptyList[JdbcType],
@@ -140,7 +140,7 @@ object Put extends PutInstances {
140140
vendorTypeNames = vendorTypeNames.toList,
141141
put = put,
142142
update = update
143-
) {}
143+
)
144144

145145
def many[A](
146146
jdbcTargets: NonEmptyList[JdbcType],

modules/core/src/main/scala/doobie/util/write.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ sealed trait Write[A] {
6666

6767
def toFragment(a: A, sql: String = List.fill(length)("?").mkString(",")): Fragment = {
6868
val elems: List[Elem] = (puts zip toList(a)).map {
69-
case ((p: Put[a], NoNulls), a) => Elem.Arg(a.asInstanceOf[a], p)
70-
case ((p: Put[a], Nullable), a) => Elem.Opt(a.asInstanceOf[Option[a]], p)
69+
case ((p, nullab), x) => nullab match {
70+
case NoNulls => p match { case px: Put[x] => Elem.Arg(x.asInstanceOf[x], px) }
71+
case Nullable => p match { case px: Put[x] => Elem.Opt(x.asInstanceOf[Option[x]], px) }
72+
}
7173
}
7274
Fragment(sql, elems, None)
7375
}

0 commit comments

Comments
 (0)