diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 158f6d284..c562b3164 100644 --- a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala +++ b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala @@ -37,6 +37,7 @@ trait MysqlSqlModule extends Sql { self => val MakeTime = FunctionDef[(Int, Int, Double), LocalTime](FunctionName("maketime")) val Now = FunctionDef[Any, ZonedDateTime](FunctionName("now")) val Pi = Expr.FunctionCall0[Double](FunctionDef[Any, Double](FunctionName("pi"))) + val Rand = FunctionDef[Int, Double](FunctionName("rand")) val RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad")) val Uuid = Expr.FunctionCall0[UUID](FunctionDef[Any, UUID](FunctionName("uuid"))) } diff --git a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala index d01eef2ce..1de247e39 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -151,6 +151,13 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { test("uuid") { assertZIO(execute(select(Uuid)).runHead.some)(!isNull) }, + test("rand") { + val query = select(Rand(5)) + + val testResult = execute(query) + + assertZIO(testResult.runHead.some)(isGreaterThanEqualTo(0d) && isLessThanEqualTo(1d)) + }, test("rpad") { val cases = Seq(("hi", 5, "?", "hi???"), ("hi", 1, "?", "h")) check(Gen.fromIterable(cases)) { case (str, len, pad, exp) =>