diff --git a/docs/data-types.html b/docs/data-types.html
index 4c586e7580..e9abb71ae1 100644
--- a/docs/data-types.html
+++ b/docs/data-types.html
@@ -538,23 +538,22 @@
val mealTime: Column<Meal> = time("meal_time").transform(MealTimeTransformer())
}
Special case is nullTransform()
method. That method applies a special transformation that allows a non-nullable database column to accept and/or return values as `null` on the client side.
This transformation does not alter the column's definition in the database, which will still be NON NULL
. It enables reflecting non-null values from the database as null
in Kotlin (e.g., converting an empty string from a non-nullable text column, empty lists, negative IDs, etc., to null
).
- class MealTimeNullTransformer : ColumnTransformer<LocalTime?, Meal?> {
- override fun wrap(value: LocalTime?): Meal? = when {
- value == null -> null
+ class MealTimeNullTransformer : ColumnTransformer<LocalTime, Meal?> {
+ override fun wrap(value: LocalTime): Meal? = when {
value.hour < 10 -> Meal.BREAKFAST
value.hour < 15 -> Meal.LUNCH
else -> Meal.DINNER
}
- override fun unwrap(value: Meal?): LocalTime? = when (value) {
+ override fun unwrap(value: Meal?): LocalTime = when (value) {
Meal.BREAKFAST -> LocalTime(8, 0)
Meal.LUNCH -> LocalTime(12, 0)
Meal.DINNER -> LocalTime(18, 0)
- else -> null
+ else -> LocalTime(0, 0)
}
}
object Meals : Table() {
- val mealTime: Column<Meal?> = time("meal_time").nullable().transform(MealTimeNullTransformer())
+ val mealTime: Column<Meal?> = time("meal_time").transform(MealTimeNullTransformer())
}
-
Last modified: 30 October 2024