English | 简体中文

api-docs / org.ktorm.entity / firstOrNull

firstOrNull

fun <E : Any, T : BaseTable<E>> EntitySequence<E, T>.firstOrNull(): E? (source code)

Return the first element, or null if the sequence is empty.

Especially, if a dialect is enabled, this function will use the pagination feature to obtain the very record only.
Assuming we are using MySQL, a SQL containing limit 0, 1 will be generated. But if there are no dialects enabled,
then all records in the sequence will be obtained to ensure the function just works.

The operation is terminal.

inline fun <E : Any, T : BaseTable<E>> EntitySequence<E, T>.firstOrNull(
    predicate: (T) -> ColumnDeclaring<Boolean>
): E?
(source code)

Return the first element matching the given predicate, or null if element was not found.

Especially, if a dialect is enabled, this function will use the pagination feature to obtain the very record only.
Assuming we are using MySQL, a SQL containing limit 0, 1 will be generated. But if there are no dialects enabled,
then all records in the sequence matching the given predicate will be obtained to ensure the function just works.

The operation is terminal.