diff --git a/docs/reference/gqlalchemy/query_builders/memgraph_query_builder.md b/docs/reference/gqlalchemy/query_builders/memgraph_query_builder.md index 081b32ac..74ed37ae 100644 --- a/docs/reference/gqlalchemy/query_builders/memgraph_query_builder.md +++ b/docs/reference/gqlalchemy/query_builders/memgraph_query_builder.md @@ -9,6 +9,24 @@ title: gqlalchemy.query_builders.memgraph_query_builder class QueryBuilder(DeclarativeBase) ``` +#### data\_directory\_lock\_status + +```python +def data_directory_lock_status() -> "DeclarativeBase" +``` + +Check whether Memgraph data directory locking is currently enabled. + +**Returns**: + + A `DeclarativeBase` instance for constructing queries. + + +**Examples**: + +- `Python` - `data_directory_lock_status().execute()` +- `Cypher` - `DATA DIRECTORY LOCK STATUS;` + #### load\_csv ```python @@ -90,6 +108,12 @@ Cypher query defining the MATCH clause which selects the nodes and relationships - `Python` - `call("export_util.json", "/home/user", subgraph_path="(:LABEL)-[:TYPE]->(:LABEL)").execute()` - `Cypher` - `MATCH p=(:LABEL)-[:TYPE1]->(:LABEL) WITH project(p) AS graph CALL export_util.json(graph, "/home/user")` +## DataDirectoryLockStatus Objects + +```python +class DataDirectoryLockStatus(DeclarativeBase) +``` + ## ProjectPartialQuery Objects ```python diff --git a/gqlalchemy/__init__.py b/gqlalchemy/__init__.py index bccf728d..1ec93d90 100644 --- a/gqlalchemy/__init__.py +++ b/gqlalchemy/__init__.py @@ -57,7 +57,11 @@ Unwind, With, ) -from gqlalchemy.query_builders.memgraph_query_builder import LoadCsv, QueryBuilder +from gqlalchemy.query_builders.memgraph_query_builder import ( + DataDirectoryLockStatus, + LoadCsv, + QueryBuilder, +) from gqlalchemy.query_builders.neo4j_query_builder import Neo4jQueryBuilder # noqa F401 from gqlalchemy.vendors.memgraph import Memgraph # noqa F401 from gqlalchemy.vendors.neo4j import Neo4j # noqa F401 @@ -74,4 +78,5 @@ foreach = Foreach return_ = Return load_csv = LoadCsv +data_directory_lock_status = DataDirectoryLockStatus MemgraphQueryBuilder = QueryBuilder diff --git a/gqlalchemy/query_builders/memgraph_query_builder.py b/gqlalchemy/query_builders/memgraph_query_builder.py index ae6f16a9..b969af84 100644 --- a/gqlalchemy/query_builders/memgraph_query_builder.py +++ b/gqlalchemy/query_builders/memgraph_query_builder.py @@ -36,9 +36,18 @@ class MemgraphQueryBuilderTypes(DeclarativeBaseTypes): + DATA_DIRECTORY_LOCK_STATUS = "DATA_DIRECTORY_LOCK_STATUS" LOAD_CSV = "LOAD_CSV" +class DataDirectoryLockStatusPartialQuery(PartialQuery): + def __init__(self): + super().__init__(MemgraphQueryBuilderTypes.DATA_DIRECTORY_LOCK_STATUS) + + def construct_query(self) -> str: + return " DATA DIRECTORY LOCK STATUS " + + class LoadCsvPartialQuery(PartialQuery): def __init__(self, path: str, header: bool, row: str): super().__init__(DeclarativeBaseTypes.LOAD_CSV) @@ -54,6 +63,21 @@ class QueryBuilder(DeclarativeBase): def __init__(self, connection: Optional[Memgraph] = None): super().__init__(connection) + def data_directory_lock_status(self) -> "DeclarativeBase": + """Check whether Memgraph data directory locking is currently enabled. + + Returns: + A `DeclarativeBase` instance for constructing queries. + + Examples: + Python: `data_directory_lock_status().execute()` + Cypher: `DATA DIRECTORY LOCK STATUS;` + """ + self._query.append(DataDirectoryLockStatusPartialQuery()) + self._fetch_results = True + + return self + def load_csv(self, path: str, header: bool, row: str) -> "DeclarativeBase": """Load data from a CSV file by executing a Cypher query for each row. @@ -200,6 +224,13 @@ def __init__(self, path: str, header: bool, row: str, connection: Optional[Datab self._query.append(LoadCsvPartialQuery(path, header, row)) +class DataDirectoryLockStatus(DeclarativeBase): + def __init__(self, connection: Optional[DatabaseClient] = None): + super().__init__(connection) + self._query.append(DataDirectoryLockStatusPartialQuery()) + self._fetch_results = True + + class ProjectPartialQuery(PartialQuery): def __init__(self, subgraph_path: str, node_labels: Optional[List[List[str]]] = None): super().__init__(DeclarativeBaseTypes.MATCH) diff --git a/tests/query_builders/test_memgraph_query_builder.py b/tests/query_builders/test_memgraph_query_builder.py index bc80c931..dbb89f44 100644 --- a/tests/query_builders/test_memgraph_query_builder.py +++ b/tests/query_builders/test_memgraph_query_builder.py @@ -15,7 +15,13 @@ import pytest from unittest.mock import patch -from gqlalchemy import InvalidMatchChainException, Memgraph, QueryBuilder +from gqlalchemy import ( + DataDirectoryLockStatus, + InvalidMatchChainException, + Memgraph, + QueryBuilder, + data_directory_lock_status, +) from gqlalchemy.query_builders.memgraph_query_builder import ( Call, Create, @@ -58,6 +64,14 @@ def test_load_csv_no_header(memgraph): mock.assert_called_with(expected_query) +def test_data_directory_lock_status(): + query_builder = QueryBuilder().data_directory_lock_status() + expected_query = " DATA DIRECTORY LOCK STATUS " + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + mock.assert_called_with(expected_query) + + def test_call_subgraph_with_labels_and_types(memgraph): label = "LABEL" types = [["TYPE1", "TYPE2"]] @@ -204,6 +218,26 @@ def test_base_class_load_csv(memgraph): mock.assert_called_with(expected_query) +def test_base_class_data_directory_lock_status(): + query_builder = DataDirectoryLockStatus() + expected_query = " DATA DIRECTORY LOCK STATUS " + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + +def test_function_data_directory_lock_status(): + query_builder = data_directory_lock_status() + expected_query = " DATA DIRECTORY LOCK STATUS " + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_bfs(): bfs_alg = BreadthFirstSearch()