Skip to content

Commit

Permalink
zio#679 fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahotoole committed May 26, 2022
2 parents f9d4521 + 61dc2e8 commit 1537a75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
8 changes: 5 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,14 +27,17 @@ 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 Hex = FunctionDef[Long, String](FunctionName("hex"))
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")))
val RPad = FunctionDef[(String, Int, String), String](FunctionName("rpad"))
}

}
35 changes: 24 additions & 11 deletions mysql/src/test/scala/zio/sql/mysql/FunctionDefSpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package zio.sql.mysql

import zio.Cause
import zio.test._
import zio.test.Assertion._

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

object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
Expand Down Expand Up @@ -76,6 +74,13 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("hex") {
val query = select(Hex(255L)) from customers
val expected = "FF"
val queryResult = execute(query)

assertZIO(queryResult.runHead.some)(equalTo(expected))
},
test("log2") {
val query = select(Log2(8d)) from customers

Expand All @@ -102,14 +107,10 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {

val testResult = execute(query)

val assertion =
for {
r <- testResult.runCollect
} yield assert(timestampFormatter.format(r.head))(
Assertion.matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}")
)

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
assertZIO(
testResult.runHead.some
.map(t => timestampFormatter.format(t))
)(matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"))
},
test("bit_length") {
val query = select(BitLength("hello"))
Expand Down Expand Up @@ -146,6 +147,18 @@ object FunctionDefSpec extends MysqlRunnableSpec with ShopSchema {
val testResult = execute(query)

assertZIO(testResult.runHead.some)(equalTo(expected))
},
test("rpad") {
val cases = Seq(("hi", 5, "?", "hi???"), ("hi", 1, "?", "h"))
check(Gen.fromIterable(cases)) { case (str, len, pad, exp) =>
assertZIO(execute(select(RPad(str, len, pad))).runHead.some)(equalTo(exp))
}
},
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 1537a75

Please sign in to comment.