Handles creation and loading of .cgc bundle files.
| 77 | |
| 78 | |
| 79 | class CGCBundle: |
| 80 | """Handles creation and loading of .cgc bundle files.""" |
| 81 | |
| 82 | VERSION = "0.1.0" # CGC bundle format version |
| 83 | |
| 84 | def __init__(self, db_manager): |
| 85 | """ |
| 86 | Initialize the CGC Bundle handler. |
| 87 | |
| 88 | Args: |
| 89 | db_manager: DatabaseManager instance for graph queries |
| 90 | """ |
| 91 | self.db_manager = db_manager |
| 92 | self._active_graph = None |
| 93 | |
| 94 | def _get_id_function(self) -> str: |
| 95 | """ |
| 96 | Get the appropriate ID function based on the database backend. |
| 97 | |
| 98 | Returns: |
| 99 | str: 'elementId' for Neo4j, 'id' for FalkorDB |
| 100 | """ |
| 101 | backend = self.db_manager.get_backend_type() |
| 102 | if backend == 'neo4j': |
| 103 | return 'elementId' |
| 104 | return 'id' |
| 105 | |
| 106 | def _uses_pk_edge_matching(self) -> bool: |
| 107 | """Kùzu/Ladybug internal IDs are not comparable via id() in MATCH.""" |
| 108 | return self.db_manager.get_backend_type() in {'kuzudb', 'ladybugdb'} |
| 109 | |
| 110 | def _node_lookup_key(self, labels, properties: Dict) -> Optional[tuple]: |
| 111 | if not labels: |
| 112 | return None |
| 113 | if isinstance(labels, str): |
| 114 | labels = [labels] |
| 115 | primary_label = labels[0] |
| 116 | pk_field = self._PK_MAP.get(primary_label) |
| 117 | if pk_field and pk_field in properties: |
| 118 | return (primary_label, pk_field, properties[pk_field]) |
| 119 | return None |
| 120 | |
| 121 | |
| 122 | def export_to_bundle( |
| 123 | self, |
| 124 | output_path: Path, |
| 125 | repo_path: Optional[Path] = None, |
| 126 | include_stats: bool = True |
| 127 | ) -> Tuple[bool, str]: |
| 128 | """ |
| 129 | Export the current graph (or a specific repository) to a .cgc bundle. |
| 130 | |
| 131 | Args: |
| 132 | output_path: Path where the .cgc file should be saved |
| 133 | repo_path: Optional specific repository path to export (None = export all) |
| 134 | include_stats: Whether to include detailed statistics |
| 135 | |
| 136 | Returns: |
no outgoing calls