transform
Transforms a column by specifying transformation functions.
Sample:
object TestTable : IntIdTable() {
val stringToInteger = integer("stringToInteger")
.transform(wrap = { it.toString() }, unwrap = { it.toInt() })
}
Return
A new column of type Wrapped with the applied transformations.
Parameters
The type into which the value of the underlying column will be transformed.
The type of the original column.
Transforms a column by specifying a transformer.
Sample:
object StringToIntListTransformer : ColumnTransformer<String, List<Int>> {
override fun wrap(value: String): List<Int> {
val result = value.split(",").map { it.toInt() }
return result
}
override fun unwrap(value: List<Int>): String = value.joinToString(",")
}
object TestTable : IntIdTable() {
val numbers = text("numbers").transform(StringToIntListTransformer)
}
Return
A new column of type Wrapped with the applied transformations.
Parameters
The type into which the value of the underlying column will be transformed.
The type of the original column.
An instance of ColumnTransformer to handle the transformations.
Transforms a nullable column by specifying transformation functions.
Sample:
object TestTable : IntIdTable() {
val nullableStringToInteger = integer("nullableStringToInteger")
.nullable()
.transform(wrap = { it?.toString() }, unwrap = { it?.toInt() })
}
Return
A new column of type Wrapped?
with the applied transformations.
Parameters
The type into which the value of the underlying column will be transformed.
The type of the original column.
Transforms a nullable column by specifying a transformer.
Sample:
object StringToIntListTransformer : ColumnTransformer<String?, List<Int>?> {
override fun wrap(value: String?): List<Int>? = value?.split(",")?.map { it.toInt() }
override fun unwrap(value: List<Int>): String = value?.joinToString(",")
}
object TestTable : IntIdTable() {
val numbers = text("numbers").nullable().transform(StringToIntListTransformer)
}
Return
A new column of type Wrapped?
with the applied transformations.
Parameters
The type into which the value of the underlying column will be transformed.
The type of the original column.
An instance of ColumnTransformer to handle the transformations.