Skip to content

Commit

Permalink
zio#656 Add maketime function to MysqlSqlModule (zio#675)
Browse files Browse the repository at this point in the history
* zio#656 Add maketime function to MysqlSqlModule

* 656 formatting

* zio#656 alphabetical order

Co-authored-by: Jakub Czuchnowski <[email protected]>
  • Loading branch information
sarahotoole and jczuchnowski authored May 26, 2022
1 parent c03e8ef commit a5f5c40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion 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.time.{ LocalDate, LocalTime, Year, ZonedDateTime }
import java.sql.ResultSet
import java.time.{ LocalDate, Year, ZonedDateTime }

import zio.sql.Sql

Expand Down Expand Up @@ -33,6 +33,7 @@ trait MysqlSqlModule extends Sql { self =>
val Degrees = FunctionDef[Double, Double](FunctionName("degrees"))
val Log2 = FunctionDef[Double, Double](FunctionName("log2"))
val Log10 = FunctionDef[Double, Double](FunctionName("log10"))
val MakeTime = FunctionDef[(Int, Int, Double), LocalTime](FunctionName("maketime"))
val Now = FunctionDef[Any, ZonedDateTime](FunctionName("now"))
val Pi = Expr.FunctionCall0[Double](FunctionDef[Any, Double](FunctionName("pi")))
}
Expand Down
15 changes: 14 additions & 1 deletion mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zio.test._
import zio.test.Assertion._
import java.time.LocalDate

import java.time.ZoneId
import java.time.{ LocalTime, ZoneId }
import java.time.format.DateTimeFormatter

object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
Expand Down Expand Up @@ -165,6 +165,19 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
},
test("maketime") {
val query = select(MakeTime(12, 15, 30.5)) from customers

val expected = LocalTime.parse("12:15:30.5")

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 a5f5c40

Please sign in to comment.