Skip to content

Commit

Permalink
Merge pull request #12 from Ecwid/bool_type
Browse files Browse the repository at this point in the history
Add support for bool type
  • Loading branch information
mvgreen authored Nov 30, 2023
2 parents 321edbd + 0653bcd commit 011c7ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?>) = array.map(::toValue)

@JvmStatic
fun toNullableArray(array: List<String?>) = array.map(::toNullableValue)

@JvmStatic
fun fromValue(value: Boolean) = value.toString()

@JvmStatic
fun fromNullableValue(value: Boolean?) = value?.toString()

@JvmStatic
fun fromArray(array: List<Boolean>) = array.map(::fromValue)

@JvmStatic
fun fromNullableArray(array: List<Boolean?>) = array.map(::fromNullableValue)
}

object Int8 {
@JvmStatic
fun toValue(str: String?) = requireNotNull(str).toByte()
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/com/ecwid/clickhouse/typed/TypedRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 011c7ad

Please sign in to comment.