diff --git a/mage/query-modules/cpp/schema.md b/mage/query-modules/cpp/schema.md new file mode 100644 index 00000000000..695809921c3 --- /dev/null +++ b/mage/query-modules/cpp/schema.md @@ -0,0 +1,114 @@ +--- +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]` ➡ 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` ➡ property name. +- `property_type: string` ➡ property type. + +#### Usage: + +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}); +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()` + +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` ➡ relationship type. +- `mandatory: boolean` ➡ a boolean which is `True` if the node has properties, `False` if the node has no properties. +- `property_name: string` ➡ property name. +- `property_type: string` ➡ property type. + +#### Usage: + +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); +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",