Example #1
0
 def _execute_query(self, query, params):
     if hasattr(self, 'tx_session'):
         self.tx_session.append(query, params or {})
         results = self.tx_session.execute()[0]
         if results:
             return [list(results[0].values)], list(results[0].columns)
         else:
             return [], None
     else:
         if not hasattr(self, 'session'):
             self.new_session()
         cq = neo4j.CypherQuery(self.session, '')
         result = neo4j.CypherResults(cq._cypher._post({'query': query, 'params': params or {}}))
         return [list(r.values) for r in result.data], list(result.columns)
Example #2
0
def cypher_query(query, params=None):
    if isinstance(query, Query):
        query = query.__str__()

    try:
        cq = neo4j.CypherQuery(connection(), '')
        start = time.clock()
        r = neo4j.CypherResults(cq._cypher._post({'query': query, 'params': params or {}}))
        end = time.clock()
        results = [list(rr.values) for rr in r.data], list(r.columns)
    except ClientError as e:
        raise CypherException(query, params, e.args[0], e.exception, e.stack_trace)

    if os.environ.get('NEOMODEL_CYPHER_DEBUG', False):
        logger.debug("query: " + query + "\nparams: " + repr(params) + "\ntook: %.2gs\n" % (end - start))

    return results
Example #3
0
def cypher_query(query, params=None):
    if isinstance(query, Query):
        query = query.__str__()
    if os.environ.get('NEOMODEL_CYPHER_DEBUG', False):
        logger.debug("query: " + query)
        logger.debug("params: " + repr(params))
    try:
        cq = neo4j.CypherQuery(connection(), '')
        r = neo4j.CypherResults(
            cq._cypher._post({
                'query': query,
                'params': params or {}
            }))
        return [list(r.values) for r in r.data], list(r.columns)
    except ClientError as e:
        raise CypherException(query, params, e.message, e.exception,
                              e.stack_trace)