-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_query_languages.py
More file actions
121 lines (92 loc) · 3.62 KB
/
Copy pathtest_query_languages.py
File metadata and controls
121 lines (92 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
Test Cypher and Gremlin examples from README.md
This script tests the simple Cypher and Gremlin examples to ensure they work correctly.
"""
from arcadedb_python import DatabaseDao, SyncClient
def test_cypher():
"""Test Cypher query language examples"""
print("\n" + "=" * 70)
print("Testing Cypher Examples")
print("=" * 70)
# Connect
client = SyncClient("localhost", 2480, username="root", password="playwithdata")
# Create or connect to database
db_name = "cypher_test"
if DatabaseDao.exists(client, db_name):
DatabaseDao.delete(client, db_name)
db = DatabaseDao.create(client, db_name)
print("[OK] Created database:", db_name)
# Create nodes
db.query("opencypher", "CREATE (p:Person {name: 'John', age: 30})", is_command=True)
db.query("opencypher", "CREATE (p:Person {name: 'Jane', age: 25})", is_command=True)
print("[OK] Created Person nodes")
# Create relationship
db.query("opencypher", """
MATCH (a:Person {name: 'John'}), (b:Person {name: 'Jane'})
CREATE (a)-[:KNOWS]->(b)
""", is_command=True)
print("[OK] Created KNOWS relationship")
# Query with openCypher
result = db.query("opencypher", "MATCH (p:Person) RETURN p.name, p.age ORDER BY p.age")
print(f"[OK] Query returned {len(result)} results:")
for row in result:
print(f" - {row}")
# Cleanup
DatabaseDao.delete(client, db_name)
print("[OK] Cleaned up database")
def test_gremlin():
"""Test Gremlin query language examples"""
print("\n" + "=" * 70)
print("Testing Gremlin Examples")
print("=" * 70)
# Connect
client = SyncClient("localhost", 2480, username="root", password="playwithdata")
# Create or connect to database
db_name = "gremlin_test"
if DatabaseDao.exists(client, db_name):
DatabaseDao.delete(client, db_name)
db = DatabaseDao.create(client, db_name)
print("[OK] Created database:", db_name)
# Need to create vertex type first for Gremlin
db.query("sql", "CREATE VERTEX TYPE Person IF NOT EXISTS", is_command=True)
print("[OK] Created Person vertex type")
# Add vertices
db.query("gremlin", "g.addV('Person').property('name', 'John').property('age', 30)", is_command=True)
db.query("gremlin", "g.addV('Person').property('name', 'Jane').property('age', 25)", is_command=True)
print("[OK] Added Person vertices")
# Query with Gremlin
result = db.query("gremlin", "g.V().hasLabel('Person').values('name')")
print(f"[OK] Query returned {len(result)} names:")
for name in result:
print(f" - {name}")
# Traversal with filter
result = db.query("gremlin", "g.V().hasLabel('Person').has('age', gt(20)).valueMap()")
print(f"[OK] Filtered query returned {len(result)} results:")
for row in result:
print(f" - {row}")
# Cleanup
DatabaseDao.delete(client, db_name)
print("[OK] Cleaned up database")
def main():
print("\n" + "=" * 70)
print("README.md Query Language Examples Test")
print("=" * 70)
try:
test_cypher()
print("\n[OK] Cypher tests passed!")
except Exception as e:
print(f"\n[FAIL] Cypher test failed: {e}")
import traceback
traceback.print_exc()
try:
test_gremlin()
print("\n[OK] Gremlin tests passed!")
except Exception as e:
print(f"\n[FAIL] Gremlin test failed: {e}")
import traceback
traceback.print_exc()
print("\n" + "=" * 70)
print("All tests completed!")
print("=" * 70)
if __name__ == "__main__":
main()