select

fun <T : KQLiteTable> T.select(vararg columns: KQLiteColumn<*>, distinct: Boolean = false): SelectStatement<T>

Begins building a SELECT query statement.

This function serves as the entry point for creating complex SELECT queries. It allows you to specify which columns to retrieve and whether to fetch only distinct rows. You can then chain other methods like where, join, orderBy, etc., to further refine the query. To execute the query and get the results, call execute() at the end of the chain.

If no columns are specified, all columns (*) from the table will be selected.

Example

// Selects distinct first names and ages from the Employees table,
// for employees older than 25, ordered by age in descending order.
val cursor =
Employees
.select(Employees.firstName, Employees.age, distinct = true)
.where { Employees.age GT 25 }
.orderBy(Employees.age, Sort.DESC)
.execute()

// Process the results
cursor.forEach { row ->
println("${row[Employees.firstName]}, ${row[Employees.age]}")
}

Return

A SelectStatement instance that can be used to further build the query.

Receiver

The KQLiteTable instance to select from.

Author

MOHAMMAD AZIM ANSARI

Parameters

columns

A variable number of KQLiteColumns to be included in the result set. If empty, all columns (*) are selected.

distinct

If true, the query will return only unique rows (SELECT DISTINCT). Defaults to false.

Type Parameters

T

The type of the KQLiteTable this query is being performed on.

See also


fun select(vararg columns: KQLiteColumn<*>, distinct: Boolean = false): Statement

Starts building a SELECT statement with the specified columns.

This is the entry point for creating a query that retrieves data from the database. The resulting Statement object can then be chained with from() to specify the table.

Example

// Select specific columns
select(Users.id, Users.name).from(Users)

// Select all columns (*)
select().from(Users)

// Select distinct values
select(Users.city, distinct = true).from(Users)

// Select independent queries
select(DATETIME(1761301829).unixepoch()).execute()
select(JSON_ARRAY_LENGTH(JSON("[10, 20]"))).execute()
select(MAX(IntLiteral(10), IntLiteral(20))).execute()

Return

A Statement object representing the initial part of the SELECT query.

Author

MOHAMMAD AZIM ANSARI

Parameters

columns

The columns to be selected in the query. This can be individual columns or a table's ALL property.

distinct

If true, the query will only return unique rows (SELECT DISTINCT). Defaults to false.

See also