diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 33d1b27c1..5bdb849ab 100644 --- a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala +++ b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala @@ -1,7 +1,7 @@ package zio.sql.mysql +import java.time.{ LocalDate, LocalTime, Year, ZonedDateTime } import java.sql.ResultSet -import java.time.{ LocalDate, Year, ZonedDateTime } import zio.sql.Sql @@ -33,6 +33,7 @@ trait MysqlSqlModule extends Sql { self => val Degrees = FunctionDef[Double, Double](FunctionName("degrees")) val Log2 = FunctionDef[Double, Double](FunctionName("log2")) val Log10 = FunctionDef[Double, Double](FunctionName("log10")) + 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"))) } diff --git a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala index 31d5cfe5b..629c3f947 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -5,7 +5,7 @@ import zio.test._ import zio.test.Assertion._ import java.time.LocalDate -import java.time.ZoneId +import java.time.{ LocalTime, ZoneId } import java.time.format.DateTimeFormatter object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { @@ -165,6 +165,19 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) }, + test("maketime") { + val query = select(MakeTime(12, 15, 30.5)) from customers + + val expected = LocalTime.parse("12:15:30.5") + + val testResult = execute(query) + + val assertion = for { + r <- testResult.runCollect + } yield assert(r.head)(equalTo(expected)) + + assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + }, test("pi") { val query = select(Pi) from customers