Skip to content
Merged
Show file tree
Hide file tree
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
110 changes: 110 additions & 0 deletions docs/how-to-guides/manage-database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# How to manage Memgraph database

Through this guide, you will learn how to use GQLAlchemy to manage your Memgraph database instance:

- [How to manage Memgraph database](#how-to-manage-memgraph-database)
- [Get storage information](#get-storage-information)
- [Get build information](#get-build-information)
- [Analyze graph statistics](#analyze-graph-statistics)
- [Analyze all labels](#analyze-all-labels)
- [Analyze specific labels](#analyze-specific-labels)
- [Delete graph statistics](#delete-graph-statistics)
- [Delete statistics for specific labels](#delete-statistics-for-specific-labels)

>If you have any more questions, join our community and ping us on [Discord](https://discord.gg/memgraph).

!!! info
To use the features below, you must [install GQLAlchemy](../installation.md) and have a running Memgraph instance. If you're unsure how to run Memgraph, check out the Memgraph [Quick start](https://memgraph.com/docs/getting-started)).

## Get storage information

To retrieve **detailed storage information** about your Memgraph instance, use the [`get_storage_info()`](../reference/gqlalchemy/vendors/memgraph.md#get_storage_info) method. It returns information such as vertex count, edge count, memory usage, and disk usage.

```python
from gqlalchemy import Memgraph

db = Memgraph()

storage_info = db.get_storage_info()
for item in storage_info:
print(item)
```

## Get build information

To retrieve **build information** about the running Memgraph instance, use the [`get_build_info()`](../reference/gqlalchemy/vendors/memgraph.md#get_build_info) method. It returns information such as the build type (optimization level).

```python
from gqlalchemy import Memgraph

db = Memgraph()

build_info = db.get_build_info()
for item in build_info:
print(item)
```

## Analyze graph statistics

Memgraph can analyze the graph to calculate statistics that help it select more optimal indexes and speed up `MERGE` operations. Use the [`analyze_graph()`](../reference/gqlalchemy/vendors/memgraph.md#analyze_graph) and [`delete_graph_statistics()`](../reference/gqlalchemy/vendors/memgraph.md#delete_graph_statistics) methods to manage these statistics.

### Analyze all labels

To **analyze statistics for all labels** in the graph:

```python
from gqlalchemy import Memgraph

db = Memgraph()

results = db.analyze_graph()
for result in results:
print(result)
```

The result includes information about each indexed label-property pair: label, property, number of estimation nodes, number of groups, average group size, chi-squared value, and average degree.

### Analyze specific labels

To **analyze statistics only for specific labels**:

```python
from gqlalchemy import Memgraph

db = Memgraph()

results = db.analyze_graph(labels=["Person", "City"])
for result in results:
print(result)
```

### Delete graph statistics

To **delete all previously calculated graph statistics**:

```python
from gqlalchemy import Memgraph

db = Memgraph()

deleted = db.delete_graph_statistics()
for item in deleted:
print(item)
```

### Delete statistics for specific labels

To **delete statistics for specific labels only**:

```python
from gqlalchemy import Memgraph

db = Memgraph()

deleted = db.delete_graph_statistics(labels=["Person"])
for item in deleted:
print(item)
```

>Hopefully, this guide has taught you how to manage your Memgraph database using GQLAlchemy. If you
>have any more questions, join our community and ping us on [Discord](https://discord.gg/memgraph).
8 changes: 8 additions & 0 deletions docs/how-to-guides/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ certain algorithm.

- [**Create a graph projection**](query-builder/graph-projection.md)

## Manage Memgraph database

GQLAlchemy provides methods for managing and inspecting your Memgraph database
instance, including retrieving storage and build information, and analyzing graph
statistics for index optimization.

- [**Manage Memgraph database**](manage-database.md)

## Transform Python graphs into Memgraph graphs

GQLAlchemy holds transformations that can transform NetworkX, PyG and DGL graphs
Expand Down
40 changes: 40 additions & 0 deletions docs/how-to-guides/query-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Through this guide, you will learn how to use the GQLAlchemy query builder to:
- [**Filter data**](#filter-data)
- [**Filter data by property comparison**](#filter-data-by-property-comparison)
- [**Filter data by property value**](#filter-data-by-property-value)
- [**Filter data with the IN operator**](#filter-data-with-the-in-operator)
- [**Filter data by label**](#filter-data-by-label)
- [**Return results**](#return-results)
- [**Return all variables from a query**](#return-all-variables-from-a-query)
Expand Down Expand Up @@ -705,6 +706,45 @@ MATCH (p:Person) WHERE p.age > 18 OR p.name = "John" RETURN *;
The `literal` keyword is used again since you want `John` to be quoted in the
Cypher query (to be saved as a string in the database).

### Filter data with the IN operator

You can use the `IN` operator to **check if a property value is contained in a list** of values.

<Tabs
defaultValue="gqlalchemy"
values={[
{label: 'GQLAlchemy', value: 'gqlalchemy'},
{label: 'Cypher', value: 'cypher'}
]}>
<TabItem value="gqlalchemy">

```python
from gqlalchemy import match
from gqlalchemy.query_builders.memgraph_query_builder import Operator

results = list(
match()
.node(labels="Person", variable="p")
.where(item="p.name", operator=Operator.IN, literal=["Alice", "Bob"])
.return_()
.execute()
)

print(results)
```

</TabItem>
<TabItem value="cypher">

```cypher
MATCH (p:Person) WHERE p.name IN ["Alice", "Bob"] RETURN *;
```

</TabItem>
</Tabs>

The `literal` keyword argument is used because you want list values to be properly quoted in the Cypher query. You can also combine `IN` with other boolean operators like `AND`, `OR`, etc.

### Filter data by label

Nodes can be filtered by their label using the `WHERE` clause instead of
Expand Down
127 changes: 64 additions & 63 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,84 @@

site_name: GQLAlchemy Documentation

markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.superfences
- admonition
- pymdownx.details
- pymdownx.superfences

theme:
name: 'material'
logo: 'assets/memgraph-logo.svg'
font:
text: 'Roboto'
code: 'Roboto Mono'
code: 'Roboto Mono'
icon:
repo: fontawesome/brands/github
palette:
primary: 'custom'
accent: 'custom'

nav:
- Getting Started: 'index.md'
- Installation: 'installation.md'
- Import data: 'import-data.md'
- How-to guides:
- Overview: 'how-to-guides/overview.md'
- Use object graph mapper: 'how-to-guides/ogm.md'
- Use query builder: 'how-to-guides/query-builder.md'
- Manage streams:
- Kafka streams: 'how-to-guides/streams/kafka-streams.md'
- Pulsar streams: 'how-to-guides/streams/pulsar-streams.md'
- Import data from different sources:
- Import table data as a graph: 'how-to-guides/loaders/import-table-data-to-graph-database.md'
- Make a custom file system importer: 'how-to-guides/loaders/make-a-custom-file-system-importer.md'
- Manage instances:
- Manage Memgraph Docker instances: 'how-to-guides/instance-runner/memgraph-docker-instance.md'
- Manage Memgraph binary instances: 'how-to-guides/instance-runner/memgraph-binary-instance.md'
- Manage database triggers: 'how-to-guides/triggers/triggers.md'
- Use on-disk storage: 'how-to-guides/on-disk-storage/on-disk-storage.md'
- Create a graph projection: 'how-to-guides/query-builder/graph-projection.md'
- Translate Python graphs:
- Import Python graphs into Memgraph: 'how-to-guides/translators/import-python-graphs.md'
- Export data from Memgraph into Python graphs: 'how-to-guides/translators/export-python-graphs.md'
- Reference:
- Overview: 'reference/gqlalchemy/overview.md'
- graph_algorithms:
- integrated_algorithms: 'reference/gqlalchemy/graph_algorithms/integrated_algorithms.md'
- query_builder: 'reference/gqlalchemy/graph_algorithms/query_builder.md'
- query_modules: 'reference/gqlalchemy/graph_algorithms/query_modules.md'
- query_builders:
- declarative_base: 'reference/gqlalchemy/query_builders/declarative_base.md'
- memgraph_query_builder: 'reference/gqlalchemy/query_builders/memgraph_query_builder.md'
- transformations:
- transformations.export:
- graph_transporter: 'reference/gqlalchemy/transformations/export/graph_transporter.md'
- transporter: 'reference/gqlalchemy/transformations/export/transporter.md'
- transformations.importing:
- graph_importer: 'reference/gqlalchemy/transformations/importing/graph_importer.md'
- loaders: 'reference/gqlalchemy/transformations/importing/loaders.md'
- transformations.translators:
- dgl_translator: 'reference/gqlalchemy/transformations/translators/dgl_translator.md'
- nx_translator: 'reference/gqlalchemy/transformations/translators/nx_translator.md'
- pyg_translator: 'reference/gqlalchemy/transformations/translators/pyg_translator.md'
- translator: 'reference/gqlalchemy/transformations/translators/translator.md'
- vendors:
- database_client: 'reference/gqlalchemy/vendors/database_client.md'
- memgraph: 'reference/gqlalchemy/vendors/memgraph.md'
- neo4j: 'reference/gqlalchemy/vendors/neo4j.md'
- connection: 'reference/gqlalchemy/connection.md'
- disk_storage: 'reference/gqlalchemy/disk_storage.md'
- exceptions: 'reference/gqlalchemy/exceptions.md'
- instance_runner: 'reference/gqlalchemy/instance_runner.md'
- models: 'reference/gqlalchemy/models.md'
- utilities: 'reference/gqlalchemy/utilities.md'
- Under the Hood:
- Overview: 'under-the-hood/overview.md'
- Python graph translators: 'under-the-hood/python-graph-translators.md'
- Changelog: 'changelog.md'
- Getting Started: 'index.md'
- Installation: 'installation.md'
- Import data: 'import-data.md'
- How-to guides:
- Overview: 'how-to-guides/overview.md'
- Use object graph mapper: 'how-to-guides/ogm.md'
- Use query builder: 'how-to-guides/query-builder.md'
- Manage streams:
- Kafka streams: 'how-to-guides/streams/kafka-streams.md'
- Pulsar streams: 'how-to-guides/streams/pulsar-streams.md'
- Import data from different sources:
- Import table data as a graph: 'how-to-guides/loaders/import-table-data-to-graph-database.md'
- Make a custom file system importer: 'how-to-guides/loaders/make-a-custom-file-system-importer.md'
- Manage instances:
- Manage Memgraph Docker instances: 'how-to-guides/instance-runner/memgraph-docker-instance.md'
- Manage Memgraph binary instances: 'how-to-guides/instance-runner/memgraph-binary-instance.md'
- Manage database triggers: 'how-to-guides/triggers/triggers.md'
- Use on-disk storage: 'how-to-guides/on-disk-storage/on-disk-storage.md'
- Create a graph projection: 'how-to-guides/query-builder/graph-projection.md'
- Manage Memgraph database: 'how-to-guides/manage-database.md'
- Translate Python graphs:
- Import Python graphs into Memgraph: 'how-to-guides/translators/import-python-graphs.md'
- Export data from Memgraph into Python graphs: 'how-to-guides/translators/export-python-graphs.md'
- Reference:
- Overview: 'reference/gqlalchemy/overview.md'
- graph_algorithms:
- integrated_algorithms: 'reference/gqlalchemy/graph_algorithms/integrated_algorithms.md'
- query_builder: 'reference/gqlalchemy/graph_algorithms/query_builder.md'
- query_modules: 'reference/gqlalchemy/graph_algorithms/query_modules.md'
- query_builders:
- declarative_base: 'reference/gqlalchemy/query_builders/declarative_base.md'
- memgraph_query_builder: 'reference/gqlalchemy/query_builders/memgraph_query_builder.md'
- transformations:
- transformations.export:
- graph_transporter: 'reference/gqlalchemy/transformations/export/graph_transporter.md'
- transporter: 'reference/gqlalchemy/transformations/export/transporter.md'
- transformations.importing:
- graph_importer: 'reference/gqlalchemy/transformations/importing/graph_importer.md'
- loaders: 'reference/gqlalchemy/transformations/importing/loaders.md'
- transformations.translators:
- dgl_translator: 'reference/gqlalchemy/transformations/translators/dgl_translator.md'
- nx_translator: 'reference/gqlalchemy/transformations/translators/nx_translator.md'
- pyg_translator: 'reference/gqlalchemy/transformations/translators/pyg_translator.md'
- tfgnn_translator: 'reference/gqlalchemy/transformations/translators/tfgnn_translator.md'
- translator: 'reference/gqlalchemy/transformations/translators/translator.md'
- vendors:
- database_client: 'reference/gqlalchemy/vendors/database_client.md'
- memgraph: 'reference/gqlalchemy/vendors/memgraph.md'
- neo4j: 'reference/gqlalchemy/vendors/neo4j.md'
- connection: 'reference/gqlalchemy/connection.md'
- disk_storage: 'reference/gqlalchemy/disk_storage.md'
- exceptions: 'reference/gqlalchemy/exceptions.md'
- instance_runner: 'reference/gqlalchemy/instance_runner.md'
- models: 'reference/gqlalchemy/models.md'
- utilities: 'reference/gqlalchemy/utilities.md'
- Under the Hood:
- Overview: 'under-the-hood/overview.md'
- Python graph translators: 'under-the-hood/python-graph-translators.md'
- Changelog: 'changelog.md'

repo_name: 'memgraph/gqlalchemy'
repo_url: 'https://github.com/memgraph/gqlalchemy'
extra_css:
- stylesheets/extra.css
- stylesheets/extra.css
Loading