Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bool type #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading