Skip to content

Commit

Permalink
params fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie1977 authored Oct 23, 2024
1 parent 5ec2540 commit afc8a35
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/uk/ac/ebi/vfb/neo4j/flybase2neo/fb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,28 @@ def cypher_escape(value):
# For numbers and booleans
return str(value).lower()

# Optionally, split dict_list into batches if needed
batch_size = 1000 # Adjust batch size as needed
for batch in chunks(dict_list, batch_size):
statements = []
for line in batch:
# Escape and substitute values into the statement template
escaped_line = {key: cypher_escape(value) for key, value in line.items()}
# Escape the values
escaped_values = {key: cypher_escape(value) for key, value in line.items()}
# Create a new dictionary with 'line.' prefixed to keys
escaped_line = {'line.' + key: value for key, value in escaped_values.items()}
try:
statement = statement_template.format(**escaped_line)
statements.append(statement)
except KeyError as e:
warnings.warn(f"Missing key {e} in line: {line}")
continue # Skip this line if a key is missing
# Optionally, print the first statement for verification
if statements:
print("First Cypher command in the batch:")
print(statements[0])
# Now send the statements via commit_list
self.nc.commit_list(statements)


def close(self):
self.conn.close() # Investigate implementing using with statement. Then method not required.

Expand Down

0 comments on commit afc8a35

Please sign in to comment.