From ff14c686dc869f063694ec47ae77a547a47a91b8 Mon Sep 17 00:00:00 2001 From: Guillaume Galy Date: Tue, 18 May 2021 09:02:19 +0200 Subject: [PATCH 1/2] Avoid narrowing the return type of the Quill probe() method --- .../src/main/scala/doobie/quill/DoobieContextBase.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/quill/src/main/scala/doobie/quill/DoobieContextBase.scala b/modules/quill/src/main/scala/doobie/quill/DoobieContextBase.scala index 50686b420..6505e2c02 100644 --- a/modules/quill/src/main/scala/doobie/quill/DoobieContextBase.scala +++ b/modules/quill/src/main/scala/doobie/quill/DoobieContextBase.scala @@ -13,8 +13,8 @@ import fs2.Stream import io.getquill.NamingStrategy import io.getquill.context.sql.idiom.SqlIdiom import io.getquill.context.StreamingContext -import java.sql.{ Connection } -import scala.util.Success +import java.sql.Connection +import scala.util.{ Success, Try } import doobie.enumerated.AutoGeneratedKeys import io.getquill.ReturnAction.{ ReturnColumns, ReturnNothing, ReturnRecord } import io.getquill.ReturnAction @@ -149,7 +149,7 @@ trait DoobieContextBase[Dialect <: SqlIdiom, Naming <: NamingStrategy] override def close(): Unit = () // Nothing to do here either. - override def probe(statement: String) = Success(()) + override def probe(statement: String): Try[_] = Success(()) // We can't implement this but it won't be called anyway so ¯\_(ツ)_/¯ override protected def withConnection[A](f: Connection => ConnectionIO[A]): ConnectionIO[A] = ??? From 3b5c15cc8135b9c215b082d3482a23484b6de084 Mon Sep 17 00:00:00 2001 From: Dmitry Polienko Date: Sun, 8 Aug 2021 22:41:46 +0700 Subject: [PATCH 2/2] Add SingleFragment.fromWrite --- modules/core/src/main/scala/doobie/syntax/string.scala | 9 ++++++--- .../core/src/test/scala/doobie/syntax/StringSuite.scala | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/core/src/main/scala/doobie/syntax/string.scala b/modules/core/src/main/scala/doobie/syntax/string.scala index 9611117e9..92c68328c 100644 --- a/modules/core/src/main/scala/doobie/syntax/string.scala +++ b/modules/core/src/main/scala/doobie/syntax/string.scala @@ -7,7 +7,7 @@ package doobie.syntax import cats.syntax.all._ import doobie.syntax.SqlInterpolator.SingleFragment -import doobie.util.Put +import doobie.util.{Put, Write} import doobie.util.fragment.{Elem, Fragment} import doobie.util.pos.Pos @@ -52,9 +52,12 @@ object SqlInterpolator { object SingleFragment { val empty = SingleFragment(Fragment.empty) - implicit def fromPut[A](a: A)(implicit put: Put[A]): SingleFragment[A] = SingleFragment(Fragment("?", Elem.Arg(a, put) :: Nil, None)) - implicit def fromPutOption[A](a: Option[A])(implicit put: Put[A]): SingleFragment[A] = SingleFragment(Fragment("?", Elem.Opt(a, put) :: Nil, None)) + @deprecated("Use fromWrite", since = "0.13.5") + def fromPut[A](a: A)(implicit put: Put[A]): SingleFragment[A] = SingleFragment(Fragment("?", Elem.Arg(a, put) :: Nil, None)) + @deprecated("Use fromWrite", since = "0.13.5") + def fromPutOption[A](a: Option[A])(implicit put: Put[A]): SingleFragment[A] = SingleFragment(Fragment("?", Elem.Opt(a, put) :: Nil, None)) implicit def fromFragment(fr: Fragment): SingleFragment[Nothing] = SingleFragment(fr) + implicit def fromWrite[A](a: A)(implicit write: Write[A]): SingleFragment[A] = SingleFragment(write.toFragment(a)) } } diff --git a/modules/core/src/test/scala/doobie/syntax/StringSuite.scala b/modules/core/src/test/scala/doobie/syntax/StringSuite.scala index caf3fc68c..30e80fb3a 100644 --- a/modules/core/src/test/scala/doobie/syntax/StringSuite.scala +++ b/modules/core/src/test/scala/doobie/syntax/StringSuite.scala @@ -32,11 +32,10 @@ class StringSuite extends munit.FunSuite { assertEquals(q.sql, "foo bar ?") } - test("sql interpolator should not support product params") { - Write[(Int, String)] - compileErrors { - """ val a = (1, "two"); sql"foo $a bar baz".query[Int] """ - } + test("sql interpolator should support product params") { + val a = (1, "two") + val q = sql"foo bar $a".query[Int] + assertEquals(q.sql, "foo bar ?,?") } }