Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 6373fc9

Browse files
feat: implement sounds like function for mysql
1 parent 15a33a3 commit 6373fc9

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ trait MysqlSqlModule extends Sql { self =>
2424
)
2525
}
2626
}
27+
28+
implicit class TStringOps[F1, F2, Source](param1: Expr[F1, Source, String]) {
29+
def `sounds like`(param2: Expr[F2, Source, String]): Expr[F1 with F2, Source, Boolean] =
30+
MysqlFunctionDef.SoundsLike(param1, param2)
31+
}
2732
}
2833

2934
object MysqlFunctionDef {
@@ -44,5 +49,6 @@ trait MysqlSqlModule extends Sql { self =>
4449
val RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad"))
4550
val Uuid = Expr.FunctionCall0[UUID](FunctionDef[Any, UUID](FunctionName("uuid")))
4651
val Radians = FunctionDef[Double, Double](FunctionName("radians"))
52+
val SoundsLike = FunctionDef[(String, String), Boolean](FunctionName("sounds like"))
4753
}
4854
}

mysql/src/test/scala/zio/sql/mysql/CustomFunctionDefSpec.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import zio.sql.table._
1212
object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {
1313

1414
import MysqlFunctionDef._
15+
import MysqlSpecific._
1516

1617
case class Customers(id: UUID, dob: LocalDate, first_name: String, last_name: String, verified: Boolean)
1718

@@ -119,6 +120,20 @@ object CustomFunctionDefSpec extends MysqlRunnableSpec with Jdbc {
119120

120121
assertZIO(testResult.runHead.some)(equalTo(expected))
121122
},
123+
test("sounds like") {
124+
val query = select(SoundsLike("Robert", "Rupert"))
125+
126+
val testResult = execute(query)
127+
128+
assertZIO(testResult.runHead.some)(equalTo(true))
129+
},
130+
test("sounds like infix") {
131+
val query = select("Robert" `sounds_like` "Rubert")
132+
133+
val testResult = execute(query)
134+
135+
assertZIO(testResult.runHead.some)(equalTo(true))
136+
},
122137
test("current_date") {
123138
val query = select(CurrentDate)
124139

0 commit comments

Comments
 (0)