From 2015e67ebfb764ce58167d68c78d397a4b66a562 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 21 Sep 2022 14:14:13 +0200 Subject: [PATCH] [jOOQ/jOOQ#14006] Add ResultQuery>.fetchMap() and fetchGroups() extension methods to jOOQ-kotlin --- .../main/kotlin/org/jooq/kotlin/Extensions.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt b/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt index 8a8f85adf3..8ba390b1d8 100644 --- a/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt +++ b/jOOQ-kotlin/src/main/kotlin/org/jooq/kotlin/Extensions.kt @@ -1,5 +1,6 @@ package org.jooq.kotlin +import org.jetbrains.annotations.Blocking import org.jooq.* import org.jooq.impl.DSL.* import java.util.stream.Collector @@ -38,6 +39,39 @@ fun > Field>.intoSet(): Field> = collecting(R fun Field>.intoSet(mapper: (R) -> E): Field> = collecting(Records.intoSet(mapper)) +// ---------------------------------------------------------------------------- +// Extensions to collect ResultQuery into other types +// ---------------------------------------------------------------------------- + +@Blocking +inline fun ResultQuery>.fetchArray(): Array = collect(Records.intoArray(E::class.java)) + +@Blocking +fun > ResultQuery.fetchGroups(): Map> = collect(Records.intoGroups()) + +@Blocking +fun > ResultQuery.fetchList(): List = collect(Records.intoList()) + +@Blocking +fun ResultQuery>.fetchMap(): Map = collect(Records.intoMap()) + +@Blocking +fun > ResultQuery.fetchSet(): Set = collect(Records.intoSet()) + +// ---------------------------------------------------------------------------- +// Extensions to collect Result into other types +// ---------------------------------------------------------------------------- + +inline fun Result>.intoArray(): Array = collect(Records.intoArray(E::class.java)) + +fun > Result.intoGroups(): Map> = collect(Records.intoGroups()) + +fun > Result.intoList(): List = collect(Records.intoList()) + +fun Result>.intoMap(): Map = collect(Records.intoMap()) + +fun > Result.intoSet(): Set = collect(Records.intoSet()) + // ----------------------------------------------------------------------------