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 all 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
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 }
amrkamel marked this conversation as resolved.
Show resolved Hide resolved
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]"))
}
)
}