diff --git a/mysql/project/build.properties b/mysql/project/build.properties new file mode 100644 index 000000000..c8fcab543 --- /dev/null +++ b/mysql/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.6.2 diff --git a/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala b/mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala index 7d027ef3e..bb7624c32 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.sql.ResultSet -import java.time.Year +import java.time.{ LocalDate, Year } import zio.sql.Sql @@ -27,12 +27,13 @@ trait MysqlSqlModule extends Sql { self => } object MysqlFunctionDef { - val Crc32 = FunctionDef[String, Long](FunctionName("crc32")) - val Degrees = FunctionDef[Double, Double](FunctionName("degrees")) - val Log2 = FunctionDef[Double, Double](FunctionName("log2")) - val Log10 = FunctionDef[Double, Double](FunctionName("log10")) - val Pi = Expr.FunctionCall0[Double](FunctionDef[Any, Double](FunctionName("pi"))) - val BitLength = FunctionDef[String, Int](FunctionName("bit_length")) + val BitLength = FunctionDef[String, Int](FunctionName("bit_length")) + val CurrentDate = Expr.ParenlessFunctionCall0[LocalDate](FunctionName("current_date")) + val Crc32 = FunctionDef[String, Long](FunctionName("crc32")) + val Degrees = FunctionDef[Double, Double](FunctionName("degrees")) + val Log2 = FunctionDef[Double, Double](FunctionName("log2")) + val Log10 = FunctionDef[Double, Double](FunctionName("log10")) + 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 dc77769df..ff54082f1 100644 --- a/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala +++ b/mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala @@ -3,6 +3,7 @@ package zio.sql.mysql import zio.Cause import zio.test._ import zio.test.Assertion._ +import java.time.LocalDate object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { @@ -131,6 +132,19 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema { assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) }, + test("current_date") { + val query = select(CurrentDate) + + val expected = LocalDate.now() + + 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