Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
Correct json parser for nodes and rels for cypher function
Browse files Browse the repository at this point in the history
  • Loading branch information
sim51 committed Dec 9, 2018
1 parent baa3dee commit 2d47f61
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions neo4jPg/neo4jPGFunction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from multicorn.utils import log_to_postgres, ERROR, WARNING, DEBUG

"""
Neo4j Postgres function
Expand All @@ -19,11 +20,10 @@ def cypher(plpy, query, params, url, login, password):

driver = GraphDatabase.driver( url, auth=basic_auth(login, password))
session = driver.session()
result = session.run(query, ast.literal_eval(params))
keys = result.keys()
for record in result:
log_to_postgres(query, ERROR)
for record in session.run(query, ast.literal_eval(params)):
jsonResult = "{"
for key in keys:
for key in record.keys():
if len(jsonResult) > 1:
jsonResult += ","
jsonResult += '"' + key + '":'
Expand Down Expand Up @@ -77,9 +77,9 @@ def node2json(node):
Convert a node to json
"""
jsonResult = "{"
jsonResult += '"id": ' + json.dumps(node.id) + ','
jsonResult += '"labels": ' + json.dumps(node.labels, default=set_default) + ','
jsonResult += '"properties": ' + json.dumps(node.properties, default=set_default)
jsonResult += '"id": ' + json.dumps(node._id) + ','
jsonResult += '"labels": ' + json.dumps(node._labels, default=set_default) + ','
jsonResult += '"properties": ' + json.dumps(node._properties, default=set_default)
jsonResult += "}"

return jsonResult
Expand All @@ -90,9 +90,9 @@ def relation2json(rel):
Convert a relation to json
"""
jsonResult = "{"
jsonResult += '"id": ' + json.dumps(rel.id) + ','
jsonResult += '"type": ' + json.dumps(rel.type) + ','
jsonResult += '"properties": ' + json.dumps(rel.properties, default=set_default)
jsonResult += '"id": ' + json.dumps(rel._id) + ','
jsonResult += '"type": ' + json.dumps(rel._type) + ','
jsonResult += '"properties": ' + json.dumps(rel._properties, default=set_default)
jsonResult += "}"

return jsonResult
Expand Down

0 comments on commit 2d47f61

Please sign in to comment.