mate_query.cpg.models.core.relationships module

This module contains implementation details; it is not part of the MATE API.

Helpers for deriving documentation and relationships from the MATE JSON schemata.

class mate_query.cpg.models.core.relationships.Direction(value)

Bases: enum.Enum

An enumeration.

IN = 'in'
OUT = 'out'
SYMMETRIC = 'symmetric'
class mate_query.cpg.models.core.relationships.EnumComparator(expression)

Bases: sqlalchemy.ext.hybrid.Comparator

A specialized SQLAlchemy Comparator for enum.Enum.

operate(op: Any, other: Any, **_kwargs: Any) Any

Operate on an argument.

This is the lowest level of operation, raises NotImplementedError by default.

Overriding this on a subclass can allow common behavior to be applied to all operations. For example, overriding ColumnOperators to apply func.lower() to the left and right side:

class MyComparator(ColumnOperators):
    def operate(self, op, other):
        return op(func.lower(self), func.lower(other))
  • op – Operator callable.

  • *other – the ‘other’ side of the operation. Will be a single scalar for most operations.

  • **kwargs – modifiers. These may be passed by special operators such as ColumnOperators.contains().

  • op (Any) –

  • other (Any) –

  • _kwargs (Any) –

Return type


mate_query.cpg.models.core.relationships.add_properties_to_node_class(cls: Type[Node]) Any

Add documentation and hybrid properties from the JSON schema to a node class.


cls (Type[Node]) –

Return type


mate_query.cpg.models.core.relationships.make_edge_relationship(cpg: CPG, edge_kind: EdgeKind, this: Type[Node], other: Type[Node], direction: Optional[Direction] = None, back_populates: Optional[str] = None, backref: Optional[str] = None) RelationshipProperty

Generate a SQLAlchemy relationship given an edge kind.

  • cpg (CPG) –

  • edge_kind (EdgeKind) –

  • this (Type[Node]) –

  • other (Type[Node]) –

  • direction (Optional[Direction]) –

  • back_populates (Optional[str]) –

  • backref (Optional[str]) –

Return type