NonNullableColumnWithTransform
A column type that handles the transformation of a nullable database column into a non-nullable Kotlin type.
Unlike NullableColumnWithTransform, which maps null database values to null on the Kotlin side, this type allows the transformer to map a null from the database to a concrete non-null value (e.g., an empty string, a default object, a sentinel value, etc.).
This enables the use-case where a nullable DB column is exposed as a non-nullable property in Kotlin, with a "special value" representing the null state.
For example:
object Users : Table() {
val description = text("description")
.nullable()
.nonNullTransform(
wrap = { it?.trim()?.ifEmpty { null } ?: "" },
unwrap = { if (it.isEmpty()) null else it }
)
}Here the DB column remains nullable, but the Kotlin type is String (non-nullable). A null in the database maps to "" on the Kotlin side, and an empty string maps back to null when written.
Parameters
The original column's IColumnType
Instance of ColumnTransformer that handles null → non-null mapping
Type Parameters
The non-nullable type to which the column value is transformed
The nullable type of the underlying database column
Constructors
Properties
Functions
Returns the SQL representation of the specified non-null value, for this column type.
Returns an object compatible with the database, from the specified non-null value, for this column type.
Defines the appearance of parameter markers in prepared SQL statements.
Recursively unwraps the given value by applying the delegate's transformation.
Function checks that provided value is suites the column type and throws IllegalArgumentException otherwise. value can be of any type (including Expression)
Converts the specified value (from the database) to an object of the appropriated type, for this column type. Default implementation returns the same instance.
Transforms a value read from the database, handling null values by mapping them to a non-nullable Wrapped value via the transformer.
Returns the SQL representation of the specified value, for this column type. If the value is null and the column is not nullable, an exception will be thrown. Used when generating an SQL statement and when logging that statement.