|
| 1 | +from dotenv import load_dotenv |
| 2 | +load_dotenv(override=True) |
| 3 | + |
| 4 | +import os |
| 5 | +from core.db.handler.memgraph import MemGraphClient |
| 6 | + |
| 7 | +db = MemGraphClient( |
| 8 | + host=os.environ.get("MEMGRAPH_URI", "localhost"), |
| 9 | + port=int(os.environ.get("MEMGRAPH_PORT", 7687)), |
| 10 | + username=os.environ.get("MEMGRAPH_USERNAME", "nullchimp"), |
| 11 | + password=os.environ.get("MEMGRAPH_PASSWORD", "nullchimp"), |
| 12 | +).connect() |
| 13 | + |
| 14 | +print("=" * 60) |
| 15 | +print("DATABASE INSPECTION") |
| 16 | +print("=" * 60) |
| 17 | + |
| 18 | +print("\n1. Total nodes:") |
| 19 | +db._cur.execute("MATCH (n) RETURN count(n) as total") |
| 20 | +result = db._cur.fetchone() |
| 21 | +print(f" Total nodes: {result[0]}") |
| 22 | + |
| 23 | +print("\n2. Node labels and counts:") |
| 24 | +db._cur.execute("MATCH (n) RETURN labels(n) as labels, count(*) as count ORDER BY count DESC") |
| 25 | +for row in db._cur.fetchall(): |
| 26 | + labels = row[0] if row[0] else ['(no label)'] |
| 27 | + print(f" {labels}: {row[1]}") |
| 28 | + |
| 29 | +print("\n3. Sample nodes (first 5):") |
| 30 | +db._cur.execute("MATCH (n) RETURN n LIMIT 5") |
| 31 | +for i, row in enumerate(db._cur.fetchall(), 1): |
| 32 | + node = row[0] |
| 33 | + print(f"\n Node {i}:") |
| 34 | + print(f" Labels: {node.labels}") |
| 35 | + print(f" Properties: {dict(node.properties)}") |
| 36 | + |
| 37 | +print("\n4. All property keys:") |
| 38 | +db._cur.execute("MATCH (n) UNWIND keys(n) as key RETURN DISTINCT key ORDER BY key") |
| 39 | +keys = [row[0] for row in db._cur.fetchall()] |
| 40 | +print(f" {', '.join(keys)}") |
| 41 | + |
| 42 | +print("\n5. Relationships:") |
| 43 | +db._cur.execute("MATCH ()-[r]->() RETURN DISTINCT type(r) as rel_type, count(*) as count ORDER BY count DESC") |
| 44 | +rels = db._cur.fetchall() |
| 45 | +if rels: |
| 46 | + for row in rels: |
| 47 | + print(f" {row[0]}: {row[1]}") |
| 48 | +else: |
| 49 | + print(" No relationships found") |
| 50 | + |
| 51 | +db.close() |
| 52 | +print("\n" + "=" * 60) |
0 commit comments