Skip to content

Commit

Permalink
Merge pull request #288 from riccardocorbella/issue/206
Browse files Browse the repository at this point in the history
Add 'date_part' function to PostgresModule
  • Loading branch information
jczuchnowski authored Jul 27, 2023
2 parents 2d96e03 + 3891a36 commit 72fa738
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ trait PostgresSqlModule extends Sql { self =>
val Chr = FunctionDef[Int, String](FunctionName("chr"))
val CurrentDate = Expr.ParenlessFunctionCall0[LocalDate](FunctionName("current_date"))
val CurrentTime = Expr.ParenlessFunctionCall0[OffsetTime](FunctionName("current_time"))
val DatePart = FunctionDef[(String, Instant), Double](FunctionName("date_part"))
val DateTrunc = FunctionDef[(String, Instant), LocalDateTime](FunctionName("date_trunc"))
val Decode = FunctionDef[(String, String), Chunk[Byte]](FunctionName("decode"))
val Degrees = FunctionDef[Double, Double](FunctionName("degrees"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,19 @@ object CustomFunctionDefSpec extends PostgresRunnableSpec with DbSchema {
Assertion.matchesRegex("[0-9]{4}-[0-9]{2}-[0-9]{2} 10:15:00.0000")
)

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
},
test("date_part") {
val instant = Instant.parse("1970-01-01T11:00:00Z")
val query = select(DatePart("hour", instant)) from customers
val testResult = execute(query)

val expected = 11d

val assertion = for {
r <- testResult.runCollect
} yield assert(r.head)(equalTo(expected))

assertion.mapErrorCause(cause => Cause.stackless(cause.untraced))
}
) @@ timeout(5.minutes)
Expand Down

0 comments on commit 72fa738

Please sign in to comment.