mgps
A module containing utility functions for general purpose tasks.
Trait | Value |
---|---|
Module type | util |
Implementation | Python |
Parallelism | sequential |
Functions
validate_predicate()
Raises an exception if the given predicate yields true
; otherwise returns
true
. This is useful when checking assertions in WHERE
clauses, because it
means you can filter out data that doesn’t meet your validation criteria, and
provide an error if the validation fails for a specific reason you want to
highlight.
Input:
predicate: boolean
➡ Predicate condition to evaluate.message: string
➡ The text of the error message raised if the predicate yieldstrue
. This can contain placeholder, such as%s
, which are interpolated from theparams
argument.params: list
➡ The list of parameters to substitute into placeholders inmessage
.
Output:
true: boolean
➡ This function either returnstrue
, or aborts the query by raising an exception.
Usage:
Use the following query to validate that age
is never negative, and to raise
an exception if the predicate is true
.
MATCH (n:User)
WHERE mgps.validate_predicate(n.age < 0, "Invalid age: %i", [n.age])
RETURN n;