Skip to content

Commit 82e654c

Browse files
authored
Merge pull request #13 from memgraph/T402-FL-rename-execute_query
Rename `execute_query` to `execute`
2 parents fb0cbcf + 69b5c67 commit 82e654c

6 files changed

Lines changed: 20 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ When working with the `gqlalchemy`, Python developer can connect to database and
4141
from gqlalchemy import Memgraph
4242

4343
memgraph = Memgraph("127.0.0.1", 7687)
44-
memgraph.execute_query("CREATE (:Node)-[:Connection]->(:Node)")
44+
memgraph.execute("CREATE (:Node)-[:Connection]->(:Node)")
4545
results = memgraph.execute_and_fetch("""
4646
MATCH (from:Node)-[:Connection]->(to:Node)
4747
RETURN from, to;

gqlalchemy/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from typing import Any, Dict, Iterator
1717

1818
import mgclient
19-
from .models import Node, Relationship, Path
19+
20+
from .models import Node, Path, Relationship
2021

2122
__all__ = ("Connection",)
2223

@@ -37,7 +38,7 @@ def __init__(
3738
self.encrypted = encrypted
3839

3940
@abstractmethod
40-
def execute_query(self, query: str) -> None:
41+
def execute(self, query: str) -> None:
4142
"""Executes Cypher query without returning any results."""
4243
pass
4344

@@ -71,7 +72,7 @@ def __init__(
7172
self.lazy = lazy
7273
self._connection = self._create_connection()
7374

74-
def execute_query(self, query: str) -> None:
75+
def execute(self, query: str) -> None:
7576
"""Executes Cypher query without returning any results."""
7677
cursor = self._connection.cursor()
7778
cursor.execute(query)

gqlalchemy/memgraph.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
from typing import Any, Dict, Iterator, List, Optional, Union
1717

1818
from .connection import Connection
19-
from .models import (
20-
MemgraphConstraint,
21-
MemgraphConstraintExists,
22-
MemgraphConstraintUnique,
23-
MemgraphIndex,
24-
)
19+
from .models import MemgraphConstraint, MemgraphConstraintExists, MemgraphConstraintUnique, MemgraphIndex
2520

2621
__all__ = ("Memgraph",)
2722

@@ -62,20 +57,20 @@ def execute_and_fetch(self, query: str, connection: Connection = None) -> Iterat
6257
connection = connection or self._get_cached_connection()
6358
return connection.execute_and_fetch(query)
6459

65-
def execute_query(self, query: str, connection: Connection = None) -> None:
60+
def execute(self, query: str, connection: Connection = None) -> None:
6661
"""Executes Cypher query without returning any results."""
6762
connection = connection or self._get_cached_connection()
68-
connection.execute_query(query)
63+
connection.execute(query)
6964

7065
def create_index(self, index: MemgraphIndex) -> None:
7166
"""Creates an index (label or label-property type) in the database"""
7267
query = f"CREATE INDEX ON {index.to_cypher()}"
73-
self.execute_query(query)
68+
self.execute(query)
7469

7570
def drop_index(self, index: MemgraphIndex) -> None:
7671
"""Drops an index (label or label-property type) in the database"""
7772
query = f"DROP INDEX ON {index.to_cypher()}"
78-
self.execute_query(query)
73+
self.execute(query)
7974

8075
def get_indexes(self) -> List[MemgraphIndex]:
8176
"""Returns a list of all database indexes (label and label-property types)"""
@@ -96,12 +91,12 @@ def ensure_indexes(self, indexes: List[MemgraphIndex]) -> None:
9691
def create_constraint(self, index: MemgraphConstraint) -> None:
9792
"""Creates a constraint (label or label-property type) in the database"""
9893
query = f"CREATE CONSTRAINT ON {index.to_cypher()}"
99-
self.execute_query(query)
94+
self.execute(query)
10095

10196
def drop_constraint(self, index: MemgraphConstraint) -> None:
10297
"""Drops a constraint (label or label-property type) in the database"""
10398
query = f"DROP CONSTRAINT ON {index.to_cypher()}"
104-
self.execute_query(query)
99+
self.execute(query)
105100

106101
def get_constraints(self) -> List[Union[MemgraphConstraintExists, MemgraphConstraintUnique]]:
107102
"""Returns a list of all database constraints (label and label-property types)"""
@@ -130,7 +125,7 @@ def ensure_constraints(self, constraints: List[Union[MemgraphConstraintExists, M
130125

131126
def drop_database(self):
132127
"""Drops database by removing all nodes and edges"""
133-
self.execute_query("MATCH (n) DETACH DELETE n")
128+
self.execute("MATCH (n) DETACH DELETE n")
134129

135130
def _get_cached_connection(self) -> Connection:
136131
"""Returns cached connection if it exists, creates it otherwise"""

gqlalchemy/transformations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _insert_queries(queries: List[str], host: str, port: int, username: str, pas
120120
while len(queries) > 0:
121121
try:
122122
query = queries.pop()
123-
memgraph.execute_query(query)
123+
memgraph.execute(query)
124124
except mgclient.DatabaseError as e:
125125
queries.append(query)
126126
logging.getLogger(__file__).warning(f"Ignoring database error: {e}")

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def populated_memgraph(dataset_file: str) -> Memgraph:
3939
memgraph.drop_database()
4040
with get_data_dir().joinpath(dataset_file).open("r") as dataset:
4141
for query in dataset:
42-
memgraph.execute_query(query)
42+
memgraph.execute(query)
4343

4444
yield memgraph
4545

tests/intergration/test_networkx.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_simple_nx_to_memgraph(memgraph: Memgraph):
4949
graph.add_edges_from([(1, 2), (1, 3)])
5050

5151
for query in nx_to_cypher(graph):
52-
memgraph.execute_query(query)
52+
memgraph.execute(query)
5353

5454
actual_nodes = list(memgraph.execute_and_fetch("MATCH (n) RETURN n ORDER BY n.id"))
5555
assert len(actual_nodes) == 3
@@ -80,7 +80,7 @@ def test_simple_index_nx_to_memgraph(memgraph: Memgraph):
8080
}
8181

8282
for query in nx_to_cypher(graph, True):
83-
memgraph.execute_query(query)
83+
memgraph.execute(query)
8484
actual_indexes = set(memgraph.get_indexes())
8585

8686
assert actual_indexes == expected_indexes
@@ -98,7 +98,7 @@ def test_nx_to_memgraph(memgraph: Memgraph):
9898
graph.add_edges_from(expected_edges)
9999

100100
for query in nx_to_cypher(graph):
101-
memgraph.execute_query(query)
101+
memgraph.execute(query)
102102

103103
actual_nodes = list(memgraph.execute_and_fetch("MATCH (n) RETURN n ORDER BY n.id"))
104104
assert len(actual_nodes) == 3
@@ -123,14 +123,14 @@ def test_big_nx_to_memgraph_with_manual_index(memgraph: Memgraph, random_nx_grap
123123
memgraph.create_index(MemgraphIndex("Label", "id"))
124124

125125
for query in nx_to_cypher(random_nx_graph):
126-
memgraph.execute_query(query)
126+
memgraph.execute(query)
127127

128128

129129
@pytest.mark.timeout(60)
130130
@pytest.mark.slow
131131
def test_big_nx_to_memgraph(memgraph: Memgraph, random_nx_graph: nx.Graph):
132132
for query in nx_to_cypher(random_nx_graph, create_index=True):
133-
memgraph.execute_query(query)
133+
memgraph.execute(query)
134134

135135

136136
@pytest.mark.timeout(240)

0 commit comments

Comments
 (0)