exists
Checks if a value is present, i.e. not null
and not empty.
The negation of empty()
.
Accepts arguments of nullable type (T?
), checking that they are not null, and of collection type (collection<T>
), checking that they contain at least one element. Where an argument is a nullable collection (collection<T>?
), it is checked both for non-nullity and non-emptiness.
Examples:
val x: integer? = null; exists(x)
returnsfalse
val y: integer? = 1; exists(y)
returnstrue
val l1: list<integer>? = null; exists(l1)
returnsfalse
val l2: list<integer>? = []; exists(l2)
returnsfalse
val l3: list<integer>? = [1]; exists(l3)
returnstrue
Note that when exists()
is used within a database at-expression, and its argument is also a database at-expression, the inner at-expression can refer to entities of the outer one, as long as the inner uses @*
(as opposed to @
, @+
or @?
). Such expressions are efficient as they can be translated into a single nested SQL query.
Inner at-expressions can use @
, @+
or @?
, but in those cases, the inner expression cannot refer to entities of the outer one, and such cases are typically slow as they cannot be translated into a single nested query. They must instead be translated into multiple SQL queries, with the existence check occurring in the Rell runtime rather than in the database, where it could be done more efficiently. The translation into multiple queries also prevents the inner expression from referencing the outer expression, as this is only possible through a translation into SQL that leverages the scoping rules of nested SQL queries.
Examples:
user @* { exists( company @* { .city == user.city } ) }
returns alluser
s who share acity
with acompany
.user @* { exists( company @* { user.city } ) }
is equivalent to the above, but uses the more concise attribute matching syntax.
Return
true
if value
is not null
and not an empty collection, false
otherwise
Since
0.6.0