Skip to content

Commit

Permalink
Add current_time function to MysqlSqlModule (#681)
Browse files Browse the repository at this point in the history
* Add current_time function to MysqlSqlModule

* fix merge mistake
  • Loading branch information
amrkamel authored May 26, 2022
1 parent 8857470 commit 223ada3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mysql/src/main/scala/zio/sql/mysql/MysqlSqlModule.scala
Original file line number Diff line number Diff line change
@@ -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 =>
Expand All @@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]"))
}
)
}

0 comments on commit 223ada3

Please sign in to comment.