Skip to content

Commit

Permalink
zio#656 Add maketime function to MysqlSqlModule
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahotoole committed May 26, 2022
1 parent bf3b198 commit 605b51e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 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.sql.ResultSet
import java.time.Year

import java.time.{LocalTime, Year}
import zio.sql.Sql

trait MysqlSqlModule extends Sql { self =>
Expand Down Expand Up @@ -33,6 +32,7 @@ trait MysqlSqlModule extends Sql { self =>
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 MakeTime = FunctionDef[(Int, Int, Double), LocalTime](FunctionName("maketime"))
}

}
15 changes: 15 additions & 0 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import zio.Cause
import zio.test._
import zio.test.Assertion._

import java.time.LocalTime

object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

import Customers._
Expand Down Expand Up @@ -142,6 +144,19 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

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))
}
)
Expand Down

0 comments on commit 605b51e

Please sign in to comment.