How to use the neomodel.core.StructuredNode function in neomodel

To help you get started, we’ve selected a few neomodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neomodel / neomodel / contrib / hierarchical.py View on Github external
def post_create(self):
        """ Called by StructuredNode class on creation of new instance. Will
            build relationship from parent to child (this) node.
        """
        if self.__parent__ and isinstance(self, StructuredNode):
            self.client.create(
                (self.__parent__.__node__, self.relationship_type(), self.__node__, {"__child__": True})
            )
github neo4j-contrib / neomodel / neomodel / contrib / semi_structured.py View on Github external
from neomodel.core import StructuredNode
from neomodel.exceptions import InflateConflict, DeflateConflict
from neomodel.util import _get_node_properties


class SemiStructuredNode(StructuredNode):
    """
    A base class allowing properties to be stored on a node that aren't
    specified in its definition. Conflicting properties are signaled with the
    :class:`DeflateConflict` exception::

        class Person(SemiStructuredNode):
            name = StringProperty()
            age = IntegerProperty()

            def hello(self):
                print("Hi my names " + self.name)

        tim = Person(name='Tim', age=8, weight=11).save()
        tim.hello = "Hi"
        tim.save() # DeflateConflict
    """
github neo4j-contrib / neomodel / neomodel / core.py View on Github external
def __eq__(self, other):
        if not isinstance(other, (StructuredNode,)):
            raise TypeError("Cannot compare neomodel node with a " + other.__class__.__name__)
        return self.__node__ == other.__node__
github neo4j-contrib / neomodel / neomodel / match.py View on Github external
def __contains__(self, obj):
        if isinstance(obj, StructuredNode):
            if hasattr(obj, 'id'):
                return self.query_cls(self).build_ast()._contains(int(obj.id))
            raise ValueError("Unsaved node: " + repr(obj))
        else:
            raise ValueError("Expecting StructuredNode instance")
github neo4j-contrib / neomodel / neomodel / match.py View on Github external
def __init__(self, source, name, definition):
        """
        Create a traversal

        """
        self.source = source

        if isinstance(source, Traversal):
            self.source_class = source.target_class
        elif inspect.isclass(source) and issubclass(source, StructuredNode):
            self.source_class = source
        elif isinstance(source, StructuredNode):
            self.source_class = source.__class__
        elif isinstance(source, NodeSet):
            self.source_class = source.source_class
        else:
            raise TypeError("Bad source for traversal: "
                            "{}".format(type(source)))

        invalid_keys = (
                set(definition) - {'direction', 'model', 'node_class', 'relation_type'}
        )
        if invalid_keys:
            raise ValueError(
                'Unallowed keys in Traversal definition: {invalid_keys}'
                .format(invalid_keys=invalid_keys)
github neo4j-contrib / neomodel / neomodel / contrib / hierarchical.py View on Github external
def children(self, cls):
        if isinstance(self, StructuredNode):
            child_nodes = [
                rel.end_node
                for rel in self.__node__.match_outgoing(cls.relationship_type())
                if rel["__child__"]
            ]
            return [cls.inflate(node) for node in child_nodes]
        else:
            return []
github neo4j-contrib / neomodel / neomodel / core.py View on Github external
def __init__(self, *args, **kwargs):
        self.__node__ = None
        super(StructuredNode, self).__init__(*args, **kwargs)
github neo4j-contrib / neomodel / neomodel / match.py View on Github external
elif isinstance(source, NodeSet):
            if inspect.isclass(source.source) and issubclass(source.source, StructuredNode):
                ident = self.build_label(source.source.__label__.lower(), source.source)
            else:
                ident = self.build_source(source.source)

            self.build_additional_match(ident, source)

            if hasattr(source, '_order_by'):
                self.build_order_by(ident, source)

            if source.filters:
                self.build_where_stmt(ident, source.filters)

            return ident
        elif isinstance(source, StructuredNode):
            return self.build_node(source)
        else:
            raise ValueError("Unknown source type " + repr(source))
github neo4j-contrib / neomodel / neomodel / match.py View on Github external
def build_source(self, source):
        if isinstance(source, Traversal):
            return self.build_traversal(source)
        elif isinstance(source, NodeSet):
            if inspect.isclass(source.source) and issubclass(source.source, StructuredNode):
                ident = self.build_label(source.source.__label__.lower(), source.source)
            else:
                ident = self.build_source(source.source)

            self.build_additional_match(ident, source)

            if hasattr(source, '_order_by'):
                self.build_order_by(ident, source)

            if source.filters:
                self.build_where_stmt(ident, source.filters)

            return ident
        elif isinstance(source, StructuredNode):
            return self.build_node(source)
        else: