Skip to content

Commit

Permalink
add support and test for gen_random_uuid() (#3855)
Browse files Browse the repository at this point in the history
* add support and test for gen_random_uuid()

* Add type

* match code style

* fix compile error

* use correct queries object

* Use postgres capable of generating uuids
  • Loading branch information
davidwheeler123 committed Feb 3, 2023
1 parent 3be35d6 commit 2e271a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Expand Up @@ -87,6 +87,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
"min" -> encapsulatingType(exprList, BLOB, TEXT, SMALL_INT, INTEGER, PostgreSqlType.INTEGER, BIG_INT, REAL).asNullable()
"date_trunc" -> encapsulatingType(exprList, TIMESTAMP_TIMEZONE, TIMESTAMP)
"now" -> IntermediateType(TIMESTAMP_TIMEZONE)
"gen_random_uuid" -> IntermediateType(PostgreSqlType.UUID)
else -> null
}

Expand Down
7 changes: 7 additions & 0 deletions dialects/postgresql/src/test/fixtures_postgresql/uuids/Test.s
@@ -0,0 +1,7 @@
CREATE TABLE uuid_test (
pk uuid
);

SELECT gen_random_uuid(), pk FROM uuid_test;

INSERT INTO uuid_test(pk) SELECT gen_random_uuid();
@@ -0,0 +1,9 @@
CREATE TABLE uuids(
key uuid NOT NULL
);

insertUuid:
INSERT INTO uuids (key) VALUES (:key);

randomUuid:
SELECT gen_random_uuid();
Expand Up @@ -16,9 +16,10 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util.UUID

class PostgreSqlTest {
val conn = DriverManager.getConnection("jdbc:tc:postgresql:9.6.8:///my_db")
val conn = DriverManager.getConnection("jdbc:tc:postgresql:latest:///my_db")
val driver = object : JdbcDriver() {
override fun getConnection() = conn
override fun closeConnection(connection: Connection) = Unit
Expand Down Expand Up @@ -186,4 +187,9 @@ class PostgreSqlTest {
insertRef(RefTable(RefTable.Id(10), id))
}
}

@Test fun genRandomUuid() {
val uuid: UUID = database.uuidsQueries.randomUuid().executeAsOne()
assertThat(uuid).isNotNull()
}
}

0 comments on commit 2e271a9

Please sign in to comment.