# transform

fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped>.transform(wrap: (Unwrapped) -> Wrapped, unwrap: (Wrapped) -> Unwrapped): Column<Wrapped>

Transforms a column by specifying transformation functions.

Sample:

    object TestTable : IntIdTable() {
        val stringToInteger = integer("stringToInteger")
            .transform(wrap = { it.toString() }, unwrap = { it.toInt() })
    }

Content copied to clipboard

#### Return

A new column of type Wrapped with the applied transformations.

#### Parameters

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.

#### Type Parameters

Wrapped

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

Unwrapped

The type of the original column.

fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped>.transform(transformer: ColumnTransformer<Unwrapped, Wrapped>): Column<Wrapped>

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)
    }

Content copied to clipboard

#### Return

A new column of type Wrapped with the applied transformations.

#### Parameters

transformer

An instance of ColumnTransformer to handle the transformations.

#### Type Parameters

Wrapped

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

Unwrapped

The type of the original column.

@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() })
    }

Content copied to clipboard

#### Return

A new column of type Wrapped`?` with the applied transformations.

#### Parameters

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.

#### Type Parameters

Wrapped

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

Unwrapped

The type of the original column.

@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)
    }

Content copied to clipboard

#### Return

A new column of type Wrapped`?` with the applied transformations.

#### Parameters

transformer

An instance of ColumnTransformer to handle the transformations.

#### Type Parameters

Wrapped

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

Unwrapped

The type of the original column.