mgps

A module containing utility functions for general purpose tasks.

TraitValue
Module typeutil
ImplementationPython
Parallelismsequential

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 yields true. This can contain placeholder, such as %s, which are interpolated from the params argument.
  • params: list ➡ The list of parameters to substitute into placeholders in message.

Output:

  • true: boolean ➡ This function either returns true, 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;