Skip to content

Allow upsert to update nodes instead of overwriting them #53

@destructivedata

Description

@destructivedata

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions