Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add current_time function to MysqlSqlModule #681

Merged
merged 6 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 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.{ LocalDate, Year }
import java.time.{ LocalDate, OffsetTime, Year }

import zio.sql.Sql

Expand All @@ -28,8 +28,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
8 changes: 8 additions & 0 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import zio.test._
import zio.test.Assertion._
import java.time.LocalDate

import java.time.format.DateTimeFormatter

object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

import Customers._
Expand Down Expand Up @@ -157,6 +159,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]"))
}
)
}