From d8457ea0dbcad4467051e374606125b39428a40c Mon Sep 17 00:00:00 2001 From: ringo Date: Wed, 29 Nov 2023 13:46:41 +0400 Subject: [PATCH] Add support for bool type --- .../com/ecwid/clickhouse/convert/Convert.kt | 26 +++++++++++++++++++ .../com/ecwid/clickhouse/typed/TypedRow.kt | 7 +++++ 2 files changed, 33 insertions(+) diff --git a/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt b/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt index 03987da..1bc9a22 100644 --- a/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt +++ b/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt @@ -6,6 +6,32 @@ import java.util.* object Convert { + object Bool { + @JvmStatic + fun toValue(str: String?) = requireNotNull(str).toBoolean() + + @JvmStatic + fun toNullableValue(str: String?) = str?.toBoolean() + + @JvmStatic + fun toArray(array: List) = array.map(::toValue) + + @JvmStatic + fun toNullableArray(array: List) = array.map(::toNullableValue) + + @JvmStatic + fun fromValue(value: Boolean) = value.toString() + + @JvmStatic + fun fromNullableValue(value: Boolean?) = value?.toString() + + @JvmStatic + fun fromArray(array: List) = array.map(::fromValue) + + @JvmStatic + fun fromNullableArray(array: List) = array.map(::fromNullableValue) + } + object Int8 { @JvmStatic fun toValue(str: String?) = requireNotNull(str).toByte() diff --git a/src/main/kotlin/com/ecwid/clickhouse/typed/TypedRow.kt b/src/main/kotlin/com/ecwid/clickhouse/typed/TypedRow.kt index f5225af..43ea1ab 100644 --- a/src/main/kotlin/com/ecwid/clickhouse/typed/TypedRow.kt +++ b/src/main/kotlin/com/ecwid/clickhouse/typed/TypedRow.kt @@ -12,6 +12,13 @@ data class TypedRow( fun getMeta() = rawRow.getMeta() + // ----------------- Bool --------------------- + + fun getBool(columnIndex: Int): Boolean { + val scalar = rawRow.getScalarValue(columnIndex) + return Convert.Bool.toValue(scalar) + } + // ----------------- INT_8 -------------------- fun getInt8(columnIndex: Int): Byte { val scalar = rawRow.getScalarValue(columnIndex)