nonNullTransform

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

Applies a special transformation that allows a nullable database column to be exposed as a non-nullable type on the Kotlin side.

This is the inverse of nullTransform, which maps a non-nullable DB column to a nullable Kotlin type.

The column remains nullable in the database schema. The transformation enables reflecting null values from the database as a concrete non-null value in Kotlin (e.g., an empty string, a default object, a sentinel value, etc.).

Sample:

object Users : Table() {
val description = text("description")
.nullable()
.nonNullTransform(
wrap = { it?.trim()?.ifEmpty { null } ?: "" },
unwrap = { if (it.isEmpty()) null else it }
)
}

Return

A new column of type Wrapped (non-nullable) with the applied transformations.

Parameters

wrap

A function to transform from the source type Unwrapped? to the target type Wrapped. Receives null when the database value is null, and must return a non-null Wrapped value.

unwrap

A function to transform from the target type Wrapped to the source type Unwrapped?. May return null to store null in the database.

Type Parameters

Wrapped

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

Unwrapped

The type of the original column (the non-null portion of the nullable column type).


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

Applies a special transformation that allows a nullable database column to be exposed as a non-nullable type on the Kotlin side.

This is the inverse of nullTransform, which maps a non-nullable DB column to a nullable Kotlin type.

The column remains nullable in the database schema. The transformation enables reflecting null values from the database as a concrete non-null value in Kotlin (e.g., an empty string, a default object, a sentinel value, etc.).

Return

A new column of type Wrapped (non-nullable) with the applied transformations.

Parameters

transformer

An instance of ColumnTransformer to handle the transformations. Its ColumnTransformer.wrap method must return a non-null value even when given null. Its ColumnTransformer.unwrap method may return null to store null in the database.

Type Parameters

Wrapped

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

Unwrapped

The type of the original column (the non-null portion of the nullable column type).