api-docs / org.ktorm.schema / SqlType / transform
transform
open fun <R : Any> transform(
fromUnderlyingValue: (T) -> R,
toUnderlyingValue: (R) -> T
): SqlType<R>
(source code)Transform this SqlType to another. The returned SqlType has the same typeCode and typeName as the
underlying one, and performs the specific transformations on column values.
This function 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 IntSqlType:
val role by registerColumn("role", IntSqlType.transform({ UserRole.fromCode(it) }, { it.code }))
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.
Return
a SqlType instance based on this underlying type with specific transformations.