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

Wrapped

The type into which the value of the underlying column will be transformed.

Unwrapped

The type of the original column.

wrap

A function to transform from the source type Unwrapped to the target type Wrapped.

unwrap

A function to transform from the target type Wrapped to the source type Unwrapped.


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

Wrapped

The type into which the value of the underlying column will be transformed.

Unwrapped

The type of the original column.

transformer

An instance of ColumnTransformer to handle the transformations.


@JvmName(name = "transformNullable")
fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped?>.transform(wrap: (Unwrapped?) -> Wrapped?, unwrap: (Wrapped?) -> Unwrapped?): Column<Wrapped?>

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

Wrapped

The type into which the value of the underlying column will be transformed.

Unwrapped

The type of the original column.

wrap

A function to transform from the source type Unwrapped to the target type Wrapped.

unwrap

A function to transform from the target type Wrapped to the source type Unwrapped.


@JvmName(name = "transformNullable")
fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped?>.transform(transformer: ColumnTransformer<Unwrapped?, Wrapped?>): Column<Wrapped?>

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

Wrapped

The type into which the value of the underlying column will be transformed.

Unwrapped

The type of the original column.

transformer

An instance of ColumnTransformer to handle the transformations.