From 29b5c6ae0e980e9ac813deade3e9d1fcf20d4fb3 Mon Sep 17 00:00:00 2001 From: Boris Burdiliak Date: Thu, 26 May 2022 15:36:54 +0200 Subject: [PATCH 1/2] support for gen_random_uuid function of PostgreSQL --- .../scala/zio/sql/postgresql/PostgresSqlModule.scala | 4 ++-- .../scala/zio/sql/postgresql/FunctionDefSpec.scala | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala index fd85d27b7..c437291e5 100644 --- a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala +++ b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala @@ -4,8 +4,7 @@ import java.sql.ResultSet import java.text.DecimalFormat import java.time._ import java.time.format.DateTimeFormatter -import java.util.Calendar - +import java.util.{Calendar, UUID} import org.postgresql.util.PGInterval import zio.Chunk import zio.sql.Sql @@ -308,6 +307,7 @@ trait PostgresSqlModule extends Sql { self => val SetSeed = FunctionDef[Double, Unit](FunctionName("setseed")) val BitLength = FunctionDef[String, Int](FunctionName("bit_length")) val Pi = Expr.FunctionCall0[Double](FunctionDef[Any, Double](FunctionName("pi"))) + val GenRandomUuid = Expr.FunctionCall0[UUID](FunctionDef[Any, UUID](FunctionName("gen_random_uuid"))) } } diff --git a/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala b/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala index 8ebcf8e5c..bf988701d 100644 --- a/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala +++ b/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala @@ -177,6 +177,17 @@ object FunctionDefSpec extends PostgresRunnableSpec with DbSchema { assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) }, + test("gen_random_uuid") { + val query = select(GenRandomUuid) + + val testResult = execute(query) + + val assertion = for { + r <- testResult.runCollect + } yield assert(r.head)(!isNull) + + assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + }, suite("format function")( test("format0") { import Expr._ From eac3323660f53b35ff979f4166b15be0259ac1f3 Mon Sep 17 00:00:00 2001 From: Boris Burdiliak Date: Thu, 26 May 2022 16:27:10 +0200 Subject: [PATCH 2/2] formatting --- .../src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala index c437291e5..817aa17e4 100644 --- a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala +++ b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala @@ -4,7 +4,7 @@ import java.sql.ResultSet import java.text.DecimalFormat import java.time._ import java.time.format.DateTimeFormatter -import java.util.{Calendar, UUID} +import java.util.{ Calendar, UUID } import org.postgresql.util.PGInterval import zio.Chunk import zio.sql.Sql