# uuid_generator

This module is used to generate string UUIDs which can be stored as properties
on nodes or edges. The underlying implementation makes use of the `uuid-dev`
library. When using the `uuid` module on Linux systems, the library can be
installed by running `sudo apt-get install uuid-dev`.

| Trait               | Value      |
| ------------------- | ---------- |
| **Module type**     | util       |
| **Implementation**  | C++        |
| **Parallelism**     | sequential |

## Procedures

> **Info**
>
> You can execute this algorithm on [graph projections, subgraphs or portions of the graph](https://memgraph.com/docs/advanced-algorithms/run-algorithms#run-procedures-on-subgraph).

### `get()`

Use the procedure to the the UUID string.

#### Input:

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](https://memgraph.com/docs/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run. 
If subgraph is not specified, the algorithm is computed on the entire graph by default.

#### Output:

* `uuid` ➡ Returns a UUID string.

#### Usage:

To get a UUID string, use the following query:

```cypher
MATCH (n)
CALL uuid_generator.get() YIELD uuid
SET n.uuid = uuid
RETURN n.uuid AS node_uuid;
```

## Example

### Database state
 

The database contains the following data: 

![](https://memgraph.com/docs/pages/advanced-algorithms/available-algorithms/uuid_generator/uuid-generator-1.png)

Created with the following Cypher queries:

```cypher
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]->(b);
```

### Get UUID
 

```cypher
MATCH (n)
CALL uuid_generator.get() YIELD uuid
SET n.uuid = uuid
RETURN n.uuid AS node_uuid;
```

Results:

```plaintext
+----------------------------------------+
| node_uuid                              |
+----------------------------------------+
| "ef4722b2-628b-4f93-8667-fc91134ed980" |
| "601faade-8c61-4dc3-a68a-693fed4ad40c" |
| "dc4283b8-90d6-402e-8fc0-f37f9959b593" |
+----------------------------------------+
```
