transform

fun <C : Any, R : Any> Column<C>.transform(fromUnderlyingValue: (C) -> R, toUnderlyingValue: (R) -> C): Column<R>(source)

Transform the registered column's SqlType to another. The transformed SqlType has the same typeCode and typeName as the underlying one, and performs the specific transformations on column values.

This enables a user-friendly syntax to extend more data types. For example, the following code defines a column of type Column<UserRole>, based on the existing column definition function int:

val role = int("role").transform({ UserRole.fromCode(it) }, { it.code })

Note: Since Column is immutable, this function will create a new Column instance and replace the origin registered one.

Return

the new Column instance with its type changed to R.

Parameters

fromUnderlyingValue

a function that transforms a value of underlying type to the user's type.

toUnderlyingValue

a function that transforms a value of user's type to the underlying type.

See also