Current Situation
In its current version the method upsert_node() simply overwrites a node if it already exists.
Possible Improvement
Nodes should only be overwritten if explicitly specified, the new default could e.g. add the new values if the field of the existing node is null. An even more elaborate approach could allow for a white-/blacklist of keys that can be overwritten.
Example
upsert_node(
self,
collection_name: str,
data: dict[str, Any],
overwrite: bool = False,
alt_key: str | list[str] | None = None
) -> Document:
# ...
if node := self.get_document(collection_name, data=data, alt_key=alt_key):
# Update existing vertex
for key, value in data.items():
if node[key] is None and value is not None:
node[key] = value
# Save updated node
node.patch()
# ...
Additional Considerations
The datasource key is currently a single str, if multiple datasources contribute to the contents of a node consider list[str] instead.
Current Situation
In its current version the method
upsert_node()simply overwrites a node if it already exists.Possible Improvement
Nodes should only be overwritten if explicitly specified, the new default could e.g. add the new values if the field of the existing node is
null. An even more elaborate approach could allow for a white-/blacklist of keys that can be overwritten.Example
Additional Considerations
The
datasourcekey is currently a singlestr, if multiple datasources contribute to the contents of a node considerlist[str]instead.