Skip to content

Commit

Permalink
Merge pull request #11 from TogetherCrew/feat/neo4j-batch-query-run
Browse files Browse the repository at this point in the history
feat: neo4j apoc.runMany added!
  • Loading branch information
amindadgar authored Sep 3, 2024
2 parents 568d8e2 + 8e6c0b7 commit 84a97eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="tc-neo4j-lib",
version="2.0.1",
version="2.0.2",
author="Mohammad Amin Dadgar, TogetherCrew",
maintainer="Mohammad Amin Dadgar",
maintainer_email="[email protected]",
Expand Down
9 changes: 8 additions & 1 deletion tc_neo4j_lib/neo4j_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def run_queries_in_batch(
with session.begin_transaction() as tx:
query_count = len(batch_queries)

apoc_run_queries: str = ""

for idx, query_item in enumerate(batch_queries):
query = query_item.query
query_parameters = query_item.parameters
Expand All @@ -111,6 +113,11 @@ def run_queries_in_batch(
logging.info(
f"{message} {msg_title}: Batch {idx + 1}/{query_count}"
)
self._run_query(tx, query, **query_parameters)

apoc_run_queries += f"CALL apoc.cypher.run('{query}', {query_parameters}); "

self._run_query(
tx, f"CALL apoc.cypher.runMany('{apoc_run_queries}', {{}})"
)
except Exception as e:
logging.error(f"Couldn't execute Neo4J DB transaction, exception: {e}")

0 comments on commit 84a97eb

Please sign in to comment.