Skip to content

Commit

Permalink
feat: implement sounds like function for mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriiBerezin committed Apr 28, 2024
1 parent 15a33a3 commit 6373fc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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 @@ -24,6 +24,11 @@ trait MysqlSqlModule extends Sql { self =>
)
}
}

implicit class TStringOps[F1, F2, Source](param1: Expr[F1, Source, String]) {
def `sounds like`(param2: Expr[F2, Source, String]): Expr[F1 with F2, Source, Boolean] =
MysqlFunctionDef.SoundsLike(param1, param2)
}
}

object MysqlFunctionDef {
Expand All @@ -44,5 +49,6 @@ trait MysqlSqlModule extends Sql { self =>
val RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad"))
val Uuid = Expr.FunctionCall0[UUID](FunctionDef[Any, UUID](FunctionName("uuid")))
val Radians = FunctionDef[Double, Double](FunctionName("radians"))
val SoundsLike = FunctionDef[(String, String), Boolean](FunctionName("sounds like"))
}
}
15 changes: 15 additions & 0 deletions mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import zio.sql.table._
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 @@ -119,6 +120,20 @@ object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {

assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("sounds like") {
val query = select(SoundsLike("Robert", "Rupert"))

val testResult = execute(query)

assertZIO(testResult.runHead.some)(equalTo(true))
},
test("sounds like infix") {
val query = select("Robert" `sounds_like` "Rubert")

val testResult = execute(query)

assertZIO(testResult.runHead.some)(equalTo(true))
},
test("current_date") {
val query = select(CurrentDate)

Expand Down

0 comments on commit 6373fc9

Please sign in to comment.