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

[master < schema] Write schema docs #1030

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
116 changes: 116 additions & 0 deletions mage/query-modules/cpp/schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
id: schema
title: schema
sidebar_label: schema
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import RunOnSubgraph from '../../templates/_run_on_subgraph.mdx';

export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
color: '#fff',
padding: '0.2rem',
}}>
{children}
</span>
);


The `schema` module offers procedures that allow you to interact with and retrieve information about the database schema.

[![docs-source](https://img.shields.io/badge/source-schema-FB6E00?logo=github&style=for-the-badge)](https://github.com/memgraph/mage/tree/main/cpp/schema_module)

| Trait | Value |
| ------------------- | ----------------------------------------------------- |
| **Module type** | <Highlight color="#FB6E00">**util**</Highlight> |
| **Implementation** | <Highlight color="#FB6E00">**C++**</Highlight> |
| **Parallelism** | <Highlight color="#FB6E00">**sequential**</Highlight> |

### Procedures

### `node_type_properties()`

This procedure returns schema information about nodes and their properties in the graph. For every property in a node, a separate row is created.

#### Output:

- `labels: List[string]` ➡ list of labels of the node.
- `mandatory: boolean` ➡ a boolean which is `True` if the node has properties, `False` if the node has no properties.
- `property_name: string` ➡ name of the property.
- `property_type: string` ➡ type of the property.


#### Usage:

Cypher for creation of graph used in example:

```cypher
CREATE (d:Dog {name: "Rex", age: 5})-[l:LOVES {how_much: "very"}]->(h:Human:Owner {name: "Carl", age: 90});
CREATE (n:NonManadatoryNode);
```
Cypher usage of the procedure:

```cypher
CALL schema.rel_type_properties() YIELD mandatory, property_name, property_type, rel_type RETURN mandatory, property_name, property_type, rel_type;
```

```plaintext
+-------------------------------------------------------------------+
| labels | mandatory | property_name | property_type |
+-------------------------------------------------------------------+
| ["Dog"] | true | age | Int |
+-------------------------------------------------------------------+
| ["Dog"] | true | name | String |
+-------------------------------------------------------------------+
| ["Human", "Owner"] | true | age | Int |
+-------------------------------------------------------------------+
| ["Human", "Owner"] | true | name | String |
+-------------------------------------------------------------------+
| ["NonManadatoryNode"] | false | | |
+-------------------------------------------------------------------+
```


### `rel_type_properties()`

This procedure returns schema information about relationships and their properties in the graph. For every property in a relationship, a separate row is created.

#### Output:

- `rel_type: string` ➡ the type of the relationship.
- `mandatory: boolean` ➡ a boolean which is `True` if the node has properties, `False` if the node has no properties.
- `property_name: string` ➡ name of the property.
- `property_type: string` ➡ type of the property.


#### Usage:

Cypher for creation of graph used in example:

```cypher
CREATE (d:Dog)-[r:RUNS_AND_PLAYS_IN {speed: 100, duration: "5 hours" }]->(p:Park);
CREATE (b:Bird)-[f:FLIES_TO]->(s:Sky);
```
Cypher usage of the procedure:

```cypher
CALL schema.rel_type_properties() YIELD rel_type, mandatory, property_name, property_type RETURN rel_type, mandatory, property_name, property_type;
```

```plaintext
+-------------------------------------------------------------------+
| labels | mandatory | property_name | property_type |
+-------------------------------------------------------------------+
| RUNS_AND_PLAYS_IN | true | duration | String |
+-------------------------------------------------------------------+
| RUNS_AND_PLAYS_IN | true | speed | Int |
+-------------------------------------------------------------------+
| FLIES_TO | false | | |
+-------------------------------------------------------------------+

```
1 change: 1 addition & 0 deletions mage/templates/_mage_spells.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
| [migrate](/mage/query-modules/python/migrate) | Python | A module that can access data from a MySQL, SQL Server or Oracle database. |
| [periodic](/mage/query-modules/cpp/periodic) | C++ | A module containing procedures for periodically running difficult and/or memory/time consuming queries. |
| rust_example | Rust | Example of a basic module with input parameters forwarding, made in Rust. |
| [schema](/mage/query-modules/cpp/schema) | C++ | A module which offers procedures that allow you to interact with and retrieve information about the database schema. |
| [uuid_generator](/mage/query-modules/cpp/uuid-generator) | C++ | A module that generates a new universally unique identifier (UUID). |


Expand Down
1 change: 1 addition & 0 deletions sidebars/sidebarsMAGE.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = {
"query-modules/cpp/pagerank",
"query-modules/cpp/pagerank-online",
"query-modules/cpp/periodic",
"query-modules/cpp/schema",
"query-modules/python/set-cover",
"query-modules/python/temporal",
"query-modules/python/temporal-graph-networks",
Expand Down