From 61dc2e878df53a11cd2d91a38eceef6d5240e67f Mon Sep 17 00:00:00 2001 From: Amr Kamel <3amr.kaml@gmail.com> Date: Thu, 26 May 2022 19:08:03 +0200 Subject: [PATCH] Add the 'rpad' function to the MysqlSqlModule (#682) * Add the 'rpad' function to the MysqlSqlModule * fix merge mistake --- mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala | 1 + mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 162c73574..cc8db34e4 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 RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad")) } } diff --git a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala index 0d76ed157..4da50d13d 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -198,6 +198,12 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) }, + test("rpad") { + val cases = Seq(("hi", 5, "?", "hi???"), ("hi", 1, "?", "h")) + check(Gen.fromIterable(cases)) { case (str, len, pad, exp) => + assertZIO(execute(select(RPad(str, len, pad))).runHead.some)(equalTo(exp)) + } + }, test("current_time") { assertZIO( execute(select(CurrentTime)).runHead.some