From d14421595dd27f7fb7e5027847d3cdf429429335 Mon Sep 17 00:00:00 2001 From: Matija Date: Mon, 11 Sep 2023 13:08:49 +0200 Subject: [PATCH 1/2] Write schema docs --- mage/query-modules/cpp/schema.md | 116 +++++++++++++++++++++++++++++++ mage/templates/_mage_spells.mdx | 1 + sidebars/sidebarsMAGE.js | 1 + 3 files changed, 118 insertions(+) create mode 100644 mage/query-modules/cpp/schema.md diff --git a/mage/query-modules/cpp/schema.md b/mage/query-modules/cpp/schema.md new file mode 100644 index 00000000000..605c82685c3 --- /dev/null +++ b/mage/query-modules/cpp/schema.md @@ -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}) => ( + +{children} + +); + + +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** | **util** | +| **Implementation** | **C++** | +| **Parallelism** | **sequential** | + +### 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 | | | ++-------------------------------------------------------------------+ + +``` diff --git a/mage/templates/_mage_spells.mdx b/mage/templates/_mage_spells.mdx index d0b89999366..e19d98b2011 100644 --- a/mage/templates/_mage_spells.mdx +++ b/mage/templates/_mage_spells.mdx @@ -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). | diff --git a/sidebars/sidebarsMAGE.js b/sidebars/sidebarsMAGE.js index 229d7e59b8b..a37162c5668 100644 --- a/sidebars/sidebarsMAGE.js +++ b/sidebars/sidebarsMAGE.js @@ -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", From 87edcbc4c44e61361ece637d312f5e20d17964cf Mon Sep 17 00:00:00 2001 From: Vlasta <95473291+vpavicic@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:14:21 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- mage/query-modules/cpp/schema.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mage/query-modules/cpp/schema.md b/mage/query-modules/cpp/schema.md index 605c82685c3..695809921c3 100644 --- a/mage/query-modules/cpp/schema.md +++ b/mage/query-modules/cpp/schema.md @@ -39,15 +39,14 @@ This procedure returns schema information about nodes and their properties in th #### Output: -- `labels: List[string]` ➡ list of labels of the node. +- `labels: List[string]` ➡ a list of node labels. - `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. - +- `property_name: string` ➡ property name. +- `property_type: string` ➡ property type. #### Usage: -Cypher for creation of graph used in example: +Cypher query used to create the graph used to showcase the procedure: ```cypher CREATE (d:Dog {name: "Rex", age: 5})-[l:LOVES {how_much: "very"}]->(h:Human:Owner {name: "Carl", age: 90}); @@ -78,19 +77,18 @@ CALL schema.rel_type_properties() YIELD mandatory, property_name, property_type, ### `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. +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. +- `rel_type: string` ➡ relationship type. - `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. - +- `property_name: string` ➡ property name. +- `property_type: string` ➡ property type. #### Usage: -Cypher for creation of graph used in example: +Cypher query used to create the graph used to showcase the procedure: ```cypher CREATE (d:Dog)-[r:RUNS_AND_PLAYS_IN {speed: 100, duration: "5 hours" }]->(p:Park);