CASE

class CASE(builder: CaseBuilder.() -> Unit) : KQLiteColumn<String>

Represents a SQL CASE expression in a KQLite query.

This class allows for conditional logic within a query, mapping to the CASE WHEN ... THEN ... ELSE ... END SQL syntax. It functions as a KQLiteColumn of type String.

Example 1:

CASE {
WHEN { status EQ 1 } THEN "Active"
WHEN { status EQ 0 } THEN "Inactive"
ELSE("Unknown")
}

Example 2:

select(
id,
name,
salary,
CASE {
WHEN { salary LT 50000 } THEN "Low"
WHEN { salary BETWEEN (50000..100000) } THEN "Medium"
ELSE("High")
} AS "salary_group",
).from(employees).execute()

Author

MOHAMMAD AZIM ANSARI

Parameters

builder

A lambda used to define the branches of the case statement using CaseBuilder.

Constructors

Link copied to clipboard
constructor(builder: CaseBuilder.() -> Unit)