Clause

sealed class Clause

A sealed class that provides a domain-specific language (DSL) for constructing SQL clauses, primarily used in WHERE and HAVING conditions. It offers a type-safe and fluent way to build complex logical expressions.

This class and its extension functions allow for creating various SQL expressions, including:

The Clause is designed to be used within the context of a statement builder (e.g., SelectStatement, UpdateStatement). It generates Expression objects that are internally translated into a SQL query string with appropriate placeholders.

Example usage in a WHERE block:

select(Employees.employeeId, Employees.firstName)
.from(Employees)
.where {
(Employees.age GTE 18) AND (Employees.firstName LIKE "J%")
}.execute()

The methods are defined as extensions on KQLiteColumn or as standalone functions within the scope of a lambda that has a Clause as its receiver.

Author

MOHAMMAD AZIM ANSARI

See also

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
abstract class Expression

Functions

Link copied to clipboard

Creates a BETWEEN expression using a Kotlin ClosedRange (e.g., 1..10).

Creates a BETWEEN expression to check if a column's value is within the range defined by two other columns.

fun <T : Any> KQLiteColumn<in T>.BETWEEN(start: T, end: T): Clause.Expression

Creates a BETWEEN expression to check if the column's value is within a specified range (inclusive).

Link copied to clipboard
infix fun KQLiteColumn<*>.EQ(selectStatement: SelectStatement<*>): Clause.Expression

Creates an equality comparison expression (=) between a column and a subquery.

infix fun <T> KQLiteColumn<T>.EQ(value: T): Clause.Expression

Creates an equality comparison expression (= or IS).

infix fun <T> KQLiteColumn<T>.EQ(value: KQLiteColumn<out T>): Clause.Expression

Creates an equality comparison expression (=) between two columns.

Link copied to clipboard
fun EXISTS(selectStatement: SelectStatement<*>): Clause.Expression

Creates an EXISTS expression to check for the existence of rows in a subquery.

Link copied to clipboard
infix fun <T : String?> KQLiteColumn<*>.GLOB(value: KQLiteColumn<out T>): Clause.Expression

Creates a GLOB pattern-matching expression, which is similar to LIKE but uses Unix-style wildcards.

Link copied to clipboard
infix fun KQLiteColumn<*>.GT(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.GT(value: T): Clause.Expression
infix fun <T> KQLiteColumn<T>.GT(value: KQLiteColumn<out T>): Clause.Expression
Link copied to clipboard
infix fun KQLiteColumn<*>.GTE(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.GTE(value: T): Clause.Expression
infix fun <T> KQLiteColumn<T>.GTE(value: KQLiteColumn<out T>): Clause.Expression
Link copied to clipboard
fun KQLiteColumn<*>.IN(selectStatement: SelectStatement<*>): Clause.Expression

Creates an IN expression to check if the column's value is present in the result set of a subquery.

fun <T> KQLiteColumn<T>.IN(vararg args: T): Clause.Expression

Creates an IN expression to check if the column's value is present in a given list of values.

Link copied to clipboard
infix fun KQLiteColumn<*>.IS(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.IS(value: T?): Clause.Expression
infix fun <T> KQLiteColumn<T>.IS(value: KQLiteColumn<out T>): Clause.Expression
Link copied to clipboard
infix fun KQLiteColumn<*>.IS_NOT(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.IS_NOT(value: T?): Clause.Expression
Link copied to clipboard
infix fun <T : String?> KQLiteColumn<*>.LIKE(value: KQLiteColumn<out T>): Clause.Expression

Creates a LIKE pattern-matching expression.

abstract fun KQLiteColumn<*>.LIKE(value: String, escape: Char? = null): Clause.Expression

Creates a LIKE pattern-matching expression with an optional ESCAPE character.

Link copied to clipboard
infix fun KQLiteColumn<*>.LT(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.LT(value: T): Clause.Expression
infix fun <T> KQLiteColumn<T>.LT(value: KQLiteColumn<out T>): Clause.Expression
Link copied to clipboard
infix fun KQLiteColumn<*>.LTE(selectStatement: SelectStatement<*>): Clause.Expression
infix fun <T> KQLiteColumn<T>.LTE(value: T): Clause.Expression
infix fun <T> KQLiteColumn<T>.LTE(value: KQLiteColumn<out T>): Clause.Expression
Link copied to clipboard
abstract fun NOT(value: KQLiteColumn<*>): Clause.Expression

abstract fun NOT(expression: Clause.Expression): Clause.Expression

Creates a logical NOT expression.

fun NOT(selectStatement: SelectStatement<*>): Clause.Expression

Creates a logical NOT expression for a subquery.

Link copied to clipboard
Link copied to clipboard
infix fun KQLiteColumn<*>.NOT_EQ(selectStatement: SelectStatement<*>): Clause.Expression

infix fun <T> KQLiteColumn<T>.NOT_EQ(value: T): Clause.Expression

Creates a non-equality comparison expression (!= or IS NOT).

Link copied to clipboard
fun NOT_EXISTS(selectStatement: SelectStatement<*>): Clause.Expression
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
infix fun <T : String?> KQLiteColumn<*>.NOT_LIKE(value: KQLiteColumn<out T>): Clause.Expression
abstract fun KQLiteColumn<*>.NOT_LIKE(value: String, escape: Char? = null): Clause.Expression
Link copied to clipboard
infix fun <T : String?> KQLiteColumn<*>.REGEXP(value: KQLiteColumn<out T>): Clause.Expression

Creates a regular expression match expression (REGEXP).

Link copied to clipboard
protected abstract fun toBetween(column: KQLiteColumn<*>, start: Any, end: Any, not: Boolean): Clause.Expression
Link copied to clipboard
protected abstract fun toIn(column: KQLiteColumn<*>, range: Iterable<Any?>, not: Boolean): Clause.Expression