Skip to content

Commit

Permalink
Code commment suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Ramon Petgrave <[email protected]>
  • Loading branch information
Alex Chantavy and ramonpetgrave64 authored Dec 9, 2022
1 parent 7458af7 commit 8021520
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cartography/graph/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class PropertyRef:
cartography takes lists of Python dicts and loads them to Neo4j. PropertyRefs allow our dynamically generated Neo4j
ingestion queries to set values for a given node or relationship property from (A) a field on the dict being
processed (PropertyRef.override=False, default), or (B) from a single variable provided by a keyword argument
(PropertyRef.override=True).
processed (PropertyRef. set_in_kwargs =False, default), or (B) from a single variable provided by a keyword argument
(PropertyRef. set_in_kwargs =True).
"""

def __init__(self, name: str, set_in_kwargs=False):
Expand All @@ -57,6 +57,11 @@ def _parameterize_name(self) -> str:
return f"${self.name}"

def __repr__(self) -> str:
"""
By default, the querybuilder will render an UNWIND query so that
the value for this property will come from the dict being processed.
If set_in_kwargs is True, then the value will instead come from kwargs.
"""
return f"item.{self.name}" if not self.set_in_kwargs else self._parameterize_name()


Expand Down
7 changes: 4 additions & 3 deletions cartography/graph/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def _build_node_properties_statement(
}
set_clause: str = _build_node_properties_statement(node_property_map)
the returned set_clause will be:
the returned set_clause will be
```
i.id = item.Id,
i.node_prop_1 = item.Prop1,
i.node_prop_2 = $Prop2
```
where `i` is a reference to the Neo4j node.
:param node_property_map: Mapping of node attribute names as str to PropertyRef objects
:param node_extra_labels: Optional list of extra labels to set on the node as str
:return: The resulting Neo4j SET clause to set the given attributes on the node
Expand Down

0 comments on commit 8021520

Please sign in to comment.