AliasTable

sealed class AliasTable(original: KQLiteTable, tblAlias: String) : KQLiteTable

Represents a table with an alias in a SQL query.

This class is used to create a temporary, alternative name for a table, which is particularly useful in JOIN operations or when a query involves the same table multiple times. It allows columns from the original table to be referenced via the alias.

Example

    // Table self join example

val m = Employees AS "m"
val e = Employees AS "e"

val manager =
m[Employees.firstName]
.CONCAT(" ")
.CONCAT(m[Employees.lastName]) AS "Manager"

val directReport =
e[Employees.firstName]
.CONCAT(" ")
.CONCAT(e[Employees.lastName]) AS "Direct report"

val cursor =
e
.select(
manager,
directReport,
).join(m, JoinType.INNER_JOIN)
.on(m[Employees.employeeId], e[Employees.reportsTo].notNull())
.where {
LENGTH(manager) GT 4
}.orderBy(manager)
.execute()

val data =
cursor
.asSequence()
.map { it[manager] to it[directReport] }
.toList()

cursor.close()

Author

MOHAMMAD AZIM ANSARI

Parameters

original

The original KQLiteTable being aliased.

tblAlias

The alias String for the table.

See also

Constructors

Link copied to clipboard
protected constructor(original: KQLiteTable, tblAlias: String)

Functions

Link copied to clipboard
abstract operator fun <T> get(column: KQLiteColumn<T>): KQLiteColumn<T>

Retrieves a column from the original table and associates it with this alias.