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)