Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

[E-create < E-idora-create] Add docs for create module #1003

Merged
merged 5 commits into from
Aug 30, 2023
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
165 changes: 165 additions & 0 deletions mage/query-modules/cpp/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,45 @@ By enabling more precise and flexible creation of nodes and relationships within

### Procedures

### `node(labels, properties)`

Provides a more flexible way of creating nodes than Cypher’s CREATE clause.

#### Input:

- `labels: List[string]` ➡ list of all the labels to be added to the new node.
- `properties: Map` ➡ map with key/value pairs to be added as new node's properties.

#### Output:

- `node: Node` ➡ new node which is added to the graph.

#### Usage:

```cypher
CALL create.node(["Person", "Programmer"], {name: "Ana", age: 20}) YIELD node RETURN node;
```

```plaintext
+----------------------------+
| node |
+----------------------------+
| { |
| "id": 1, |
| "labels": [ |
| "Person", |
| "Programmer" |
| ], |
| "properties": { |
| name: "Ana", |
| age: 20 |
| }, |
| "type": "node" |
| } |
+----------------------------+
```


### `nodes(labels, properties)`

Create nodes with given labels and properties. For each property map, a separate node is created.
Expand Down Expand Up @@ -98,6 +137,59 @@ CALL create.set_property([d,id(h)],"property", 50) YIELD node RETURN node;
+---------------------------------------------------------------------------------------------------------------------+
```

### `set_properties(input_nodes, input_keys, input_values)`

Adds the provided properties to the node(s).

#### Input:

- `input_nodes: Any` ➡ node, node's id or a list of nodes and nodes' ids.
- `input_keys: List[string]` ➡ list of all the property keys to be added to the node(s).
- `input_values: List[Any]` ➡ list of all the corresponding property values to be added to the node(s).

#### Output:

- `node: Node` ➡ node(s) with new properties.

#### Usage:

```cypher
CREATE (:Student {name: "Ana"});
CREATE (:Student {name: "Maria"});
MATCH (s:Student) CALL create.set_properties(s, ["age", "grade"], [20, "1st"]) YIELD node RETURN node;
```

```plaintext
+----------------------------+
| node |
+----------------------------+
| { |
| "id": 1, |
| "labels": [ |
| "Student" |
| ], |
| "properties": { |
| name: "Ana", |
| age: 20, |
| grade: "1st" |
| }, |
| "type": "node" |
| } |
+----------------------------+
| { |
| "id": 2, |
| "labels": [ |
| "Student" |
| ], |
| "properties": { |
| name: "Maria", |
| age: 20, |
| grade: "1st" |
| }, |
| "type": "node" |
| } |
+----------------------------+
```

### `remove_properties(nodes, list_keys)`

Expand Down Expand Up @@ -130,6 +222,79 @@ CALL create.remove_properties([d,id(h)],["property", "property2"]) YIELD node RE
+---------------------------------------------------------------------------------------------------------------------+
```

### `set_rel_property(input_rel, input_key, input_value)`

Adds the provided property to the relationship(s).

#### Input:

- `input_rel: Any` ➡ relationship, relationship's id or a list of relationships and relationships' ids.
- `input_key: string` ➡ property key to be added to the relationship(s).
- `input_value: Any` ➡ corresponding property value to be added to the relationship(s).

#### Output:

- `relationship: Relationship` ➡ relationship(s) with new property.

#### Usage:

```cypher
MERGE (s1:Student) MERGE (s2:Student) CREATE (s1)-[k:KNOWS]->(s2);
MATCH (:Student)-[k:KNOWS]->(:Student) CALL create.set_rel_property(k, "since", 2020)
YIELD relationship RETURN relationship;
```

```plaintext
+----------------------------+
| relationship |
+----------------------------+
| { |
| "id": 1, |
| "start": 1, |
| "end": 2, |
| "label": "KNOWS", |
| "properties": { |
| since: 2020 |
| }, |
| "type": "relationship" |
| } |
+----------------------------+
```

### `remove_labels(labels, nodes)`

Removes the provided labels from the node(s).

#### Input:

- `nodes: Any` ➡ node, node's id or a list of nodes and nodes' ids.
- `labels: List[string]` ➡ list of labels to be removed (if exist) from the nodes(s).

#### Output:

- `nodes: Node` ➡ node(s) without provided labels.

#### Usage:

```cypher
CREATE (:Person:Student:Programmer {name: "Ana"});
MATCH (p:Person) CALL create.remove_labels(p, ["Student", "Engineer"]) YIELD nodes RETURN nodes;
```

```plaintext
+----------------------------+
| nodes |
+----------------------------+
| { |
| "id": 1, |
| "labels": [ |
| "Person", |
| "Programmer", |
| ], |
| "properties": { |
| name: "Ana" |
| }, |
| "type": "node" |
| } |
+----------------------------+
```