English | 简体中文

api-docs / org.ktorm.entity / mapColumns

mapColumns

inline fun <E : Any, T : BaseTable<E>, C : Any> EntitySequence<E, T>.mapColumns(
    isDistinct: Boolean = false,
    columnSelector: (T) -> ColumnDeclaring<C>
): List<C?>
(source code)

Customize the selected columns of the internal query by the given columnSelector function, and return a List
containing the query results.

This function is similar to EntitySequence.map, but the columnSelector closure accepts the current table
object T as the parameter, so what we get in the closure by it is the table object instead of an entity
element. Besides, the function’s return type is ColumnDeclaring<C>, and we should return a column or expression
to customize the select clause of the generated SQL.

Ktorm also supports selecting two or more columns, we just need to wrap our selected columns by tupleOf
in the closure, then the function’s return type becomes List<TupleN<C1?, C2?, .. Cn?>>.

The operation is terminal.

Parameters

isDistinct - specify if the query is distinct, the generated SQL becomes select distinct if it’s set to true.

columnSelector - a function in which we should return a column or expression to be selected.

Return
a list of the query results.