Skip to content

Commit

Permalink
Add Current Date Function to MySql module
Browse files Browse the repository at this point in the history
* Add Current Date Function

* Add FunctionDef

* Add Test for Current Date

* Adding imports

* Adding back imports

* Remove Parameter for CurrentDate function

* Rearrange functions to alphabetical order
  • Loading branch information
AdityaVetukuri authored May 26, 2022
1 parent 4969605 commit adc7a58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions mysql/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.2
15 changes: 8 additions & 7 deletions mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")))
}

}
14 changes: 14 additions & 0 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit adc7a58

Please sign in to comment.