(element)
| 92 | db_manager = manager |
| 93 | |
| 94 | def _get_eid(element): |
| 95 | if element is None: return None |
| 96 | if isinstance(element, (int, str)): |
| 97 | return str(element) |
| 98 | |
| 99 | # If element is a dict (like Neo4j returned items or KuzuDB node/rel dicts) |
| 100 | if isinstance(element, dict): |
| 101 | # KuzuDB _src / _dst are directly {'offset': X, 'table': Y} |
| 102 | if 'offset' in element and 'table' in element: |
| 103 | return f"{element.get('table')}_{element.get('offset')}" |
| 104 | |
| 105 | for key in ['_id', 'id', 'element_id']: |
| 106 | if key in element: |
| 107 | val = element[key] |
| 108 | if val is not None: |
| 109 | # KuzuDB returns dict IDs like {'offset': 1, 'table': 0} inside nodes |
| 110 | if isinstance(val, dict): |
| 111 | return f"{val.get('table', 0)}_{val.get('offset', 0)}" |
| 112 | return str(val) |
| 113 | return str(id(element)) |
| 114 | |
| 115 | # Try various ways to get ID (Neo4j, FalkorDB, etc. objects) |
| 116 | for attr in ['element_id', 'id', '_id']: |
| 117 | if hasattr(element, attr): |
| 118 | val = getattr(element, attr) |
| 119 | if val is not None: |
| 120 | # KuzuDB objects if any |
| 121 | if isinstance(val, dict): |
| 122 | return f"{val.get('table', 0)}_{val.get('offset', 0)}" |
| 123 | return str(val) |
| 124 | return str(id(element)) |
| 125 | |
| 126 | |
| 127 | @app.get("/api/graph") |
no test coverage detected