Example #1
0
from neo4j import contextmanager
from re import escape
from django.conf import settings

manager = contextmanager.Neo4jDBConnectionManager(settings.NEO4J_RESOURCE_URI,
                                                  settings.NEO4J_USERNAME,
                                                  settings.NEO4J_PASSWORD)


def get_node(handle_id, label):
    q = 'MATCH (n:%s { handle_id: {handle_id} }) RETURN n' % label  # Ugly hack
    try:
        with manager.read as r:
            for n in r.execute(q, handle_id=handle_id).fetchone():
                return n
    except IndexError:
        return {}


def delete_node(handle_id, label):
    q = '''
        MATCH (n:%s { handle_id: {handle_id} })
        OPTIONAL MATCH (n)-[r]-()
        DELETE n, r
        ''' % label
    with manager.transaction as w:
        w.execute(q, handle_id=handle_id)


def get_unique_node(label, key, value):
    q = 'MATCH (n:%s {%s: {value}}) RETURN n LIMIT 1' % (label, key)
Example #2
0
__author__ = 'lundberg'

from neo4j import contextmanager
from re import escape

manager = contextmanager.Neo4jDBConnectionManager("http://localhost:7474")


def get_node(handle_id, label):
    q = 'MATCH (n:%s { handle_id: {handle_id} }) RETURN n' % label  # Ugly hack
    try:
        with manager.read as r:
            for n in r.execute(q, handle_id=handle_id).fetchone():
                return n
    except IndexError:
        return {}


def delete_node(handle_id, label):
    q = '''
        MATCH (n:%s { handle_id: {handle_id} })
        OPTIONAL MATCH (n)-[r]-()
        DELETE n, r
        ''' % label
    with manager.transaction as w:
        w.execute(q, handle_id=handle_id)


def get_unique_node(label, key, value):
    q = 'MATCH (n:%s {%s: {value}}) RETURN n LIMIT 1' % (label, key)
    with manager.read as r: