Skip to content

Commit

Permalink
feat: move soundsLike to Mysql module
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriiBerezin committed Apr 29, 2024
1 parent d83b2e0 commit f64e39b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions core/jvm/src/main/scala/zio/sql/expr/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f64e39b

Please sign in to comment.