Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion gqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,4 +78,5 @@
foreach = Foreach
return_ = Return
load_csv = LoadCsv
data_directory_lock_status = DataDirectoryLockStatus
MemgraphQueryBuilder = QueryBuilder
31 changes: 31 additions & 0 deletions gqlalchemy/query_builders/memgraph_query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down Expand Up @@ -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)
Expand Down
36 changes: 35 additions & 1 deletion tests/query_builders/test_memgraph_query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]]
Expand Down Expand Up @@ -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()

Expand Down