From 223ada335527f34e9bbeaaa732d9a7b225c739bd Mon Sep 17 00:00:00 2001 From: Amr Kamel <3amr.kaml@gmail.com> Date: Thu, 26 May 2022 18:50:14 +0200 Subject: [PATCH] Add current_time function to MysqlSqlModule (#681) * Add current_time function to MysqlSqlModule * fix merge mistake --- mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala | 6 +++--- mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 5bdb849ab..6b9d2034d 100644 --- a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala +++ b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala @@ -1,8 +1,7 @@ package zio.sql.mysql -import java.time.{ LocalDate, LocalTime, Year, ZonedDateTime } import java.sql.ResultSet - +import java.time.{ LocalDate, LocalTime, OffsetTime, Year, ZonedDateTime } import zio.sql.Sql trait MysqlSqlModule extends Sql { self => @@ -28,8 +27,9 @@ trait MysqlSqlModule extends Sql { self => object MysqlFunctionDef { val BitLength = FunctionDef[String, Int](FunctionName("bit_length")) - val CurrentDate = Expr.ParenlessFunctionCall0[LocalDate](FunctionName("current_date")) val Crc32 = FunctionDef[String, Long](FunctionName("crc32")) + val CurrentDate = Expr.ParenlessFunctionCall0[LocalDate](FunctionName("current_date")) + val CurrentTime = Expr.ParenlessFunctionCall0[OffsetTime](FunctionName("current_time")) val Degrees = FunctionDef[Double, Double](FunctionName("degrees")) val Log2 = FunctionDef[Double, Double](FunctionName("log2")) val Log10 = FunctionDef[Double, Double](FunctionName("log10")) diff --git a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala index 629c3f947..671ac0cc7 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -190,6 +190,12 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { } yield assert(r.head)(equalTo(expected)) assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + }, + test("current_time") { + assertZIO( + execute(select(CurrentTime)).runHead.some + .map(t => DateTimeFormatter.ofPattern("HH:mm:ss").format(t)) + )(matchesRegex("(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]")) } ) }