From f64e39b20f7960278ce8980593fbc7c3aab66945 Mon Sep 17 00:00:00 2001 From: Grigorii Berezin Date: Mon, 29 Apr 2024 08:27:22 +0300 Subject: [PATCH] feat: move soundsLike to Mysql module --- core/jvm/src/main/scala/zio/sql/expr/Expr.scala | 5 ----- mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala | 6 ++++++ .../test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/jvm/src/main/scala/zio/sql/expr/Expr.scala b/core/jvm/src/main/scala/zio/sql/expr/Expr.scala index 415097e3b..178e58b20 100644 --- a/core/jvm/src/main/scala/zio/sql/expr/Expr.scala +++ b/core/jvm/src/main/scala/zio/sql/expr/Expr.scala @@ -67,11 +67,6 @@ sealed trait Expr[-F, -A, +B] { self => ): Expr[F with F2, A1, Boolean] = Expr.Relational(self, that, RelationalOp.LessThanEqual) - def soundsLike[F2, A1 <: A](that: Expr[F2, A1, String])(implicit - ev: B <:< String - ): Expr[F with F2, A1, Boolean] = - Expr.Relational(self, that, RelationalOp.MySqlExtensions.SoundsLike) - def like[F2, A1 <: A](that: Expr[F2, A1, String])(implicit ev: B <:< String): Expr[F with F2, A1, Boolean] = Expr.Relational(self, that, RelationalOp.Like) diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 6b116f2ce..975f68305 100644 --- a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala +++ b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala @@ -6,6 +6,7 @@ import java.util.UUID import zio.sql.Sql import zio.sql.select._ import zio.sql.expr._ +import zio.sql.ops.Operator.RelationalOp import zio.sql.typetag._ trait MysqlSqlModule extends Sql { self => @@ -24,6 +25,11 @@ trait MysqlSqlModule extends Sql { self => ) } } + + implicit class ExprOps[F1, A1, B](expr: Expr[F1, A1, B]) { + def soundsLike[F2, A2 <: A1](that: Expr[F2, A2, B])(implicit ev: B <:< String): Expr[F1 with F2, A2, Boolean] = + Expr.Relational(expr, that, RelationalOp.MySqlExtensions.SoundsLike) + } } object MysqlFunctionDef { diff --git a/mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala index 3d17afc95..bcf4dad1c 100644 --- a/mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala @@ -15,6 +15,7 @@ import java.util.UUID object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc { import MysqlFunctionDef._ + import MysqlSpecific._ case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean) @@ -123,7 +124,7 @@ object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc { assertZIO(testResult.runHead.some)(equalTo(expected)) }, test("sounds like") { - val query = select("Robert".soundsLike("Rupert")) + val query = select(literal("Robert").soundsLike("Rupert")) val testResult = execute(query)