Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion mage/query-modules/cpp/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ CALL create.nodes(["Human", "Soldier"], [{branch: "Marines", MOS: "Gunner"}, {br
+---------------------------------------------------------------------------------------------------------------------+
```


### `set_property(nodes, key, value)`

Sets the property of the input node(s), based on the provided key-value pair. If the property doesn't exist, creates a new one. Input node(s) can be a single node, node ID, or a list of nodes and node IDs. Otherwise, an exception is thrown.
Expand Down Expand Up @@ -298,3 +297,128 @@ MATCH (p:Person) CALL create.remove_labels(p, ["Student", "Engineer"]) YIELD nod
| } |
+----------------------------+
```

### `relationship(from, relationshipType, properties, to)`

Creates a new relationship with the given type and properties directed from->to.

#### Input:

- `from: Node` ➡ tail node
- `relationshipType: string` ➡ relationship type
- `properties: Map` ➡ properties of the new relationship(s)
- `to: Node` ➡ head node

#### Output:

- `relationship: Relationship` ➡ the new relationship(s)

#### Usage:

```cypher
CREATE (p:Person {name: "Cillian Murphy"});
CREATE (m:Movie {title:"Oppenheimer"});

MATCH (p:Person {name: "Cillian Murphy"}) MATCH (m:Movie {title: "Oppenheimer"}) CALL create.relationship(p, "ACTED_IN", {roles:['Oppenheimer']}, m) YIELD relationship RETURN relationship;
```

```plaintext
+-----------------------------+
| relationship |
+-----------------------------+
| { |
| "id": 0, |
| "start": 0 |
| "end": 0 |
| "label": "Acted_in" |
| "properties": { |
| roles: ["Oppenhimer"] |
| }, |
| "type": "relationship" |
| } |
+-----------------------------+
```

### `set_rel_properties(relationships, keys, values)`

Adds the provided properties to the given relationships and returns the modified relationships. If the property already exists it is modified.

#### Input:

- `relationships: int|Relationship|List[int|Relationship]` ➡ relationships to be modified given by their object or id
- `keys: List[string]` ➡ list of all the property keys to be added to the relationship(s)
- `values: List[Any]` ➡ list of all the corresponding property values to be added to the relationship(s)

#### Output:

- `relationship: Relationship` ➡ the modified relationship(s)

#### Usage:

```cypher
CREATE (idora:Person {name: "Idora"})
CREATE (ivan:Person {name: "Ivan"})
CREATE (ivan)-[:Friend {since:"long ago"}]->(idora);

MATCH (:Person)-[friends:Friend]->(:Person) CALL create.set_rel_properties(friends, ["really", "until"], [true, "forever"]) YIELD relationship RETURN relationship
```

```plaintext
+----------------------------+
| relationship |
+----------------------------+
| { |
| "id": 0, |
| "start": 1, |
| "end": 0, |
| "label": "Friend", |
| "properties": { |
| "really": true, |
| "since": "long ago", |
| "until": "forever" |
| }, |
| "type": "relationship" |
| } |
+----------------------------+
```

### `remove_rel_properties(relationships, keys)`

Removes the provided properties from the given relationships and returns the modified relationships. If a property doesn't exist in the given relationship nothing happens with it.

#### Input:

- `relationships: int|Relationship|List[int|Relationship]` ➡ relationships to be modified
- `keys: List[string]` ➡ list of property names to be removed from the given relationships

#### Output:

- `relationship: Relationship` ➡ modified relationship(s)

#### Usage:

```cypher
CREATE (matija:Person {name: "Matija"})
CREATE (ivan:Person {name: "Ivan"})
CREATE (ivan)-[:Friend {since: 'forever and ever', until: 'forever'}]->(matija);

MATCH (:Person)-[friends:Friend]->(:Person) CALL create.remove_rel_properties(friends, ["until"]) YIELD relationship return relationship;

```

```plaintext
+------------------------------------+
| relationship |
+------------------------------------+
| { |
| "id": 0, |
| "start: 1, |
| "end": 0, |
| "label": "Friend", |
| "properties": { |
| "since": "forever and ever" |
| }, |
| "type": "relationship" |
| } |
+------------------------------------+
```