|
13 | 13 | from graphrag_storage.storage_type import StorageType |
14 | 14 |
|
15 | 15 |
|
16 | | -class _StorageFactory(Factory[Storage]): |
| 16 | +class StorageFactory(Factory[Storage]): |
17 | 17 | """A factory class for storage implementations.""" |
18 | 18 |
|
19 | 19 |
|
20 | | -storage_factory = _StorageFactory() |
| 20 | +storage_factory = StorageFactory() |
21 | 21 |
|
22 | 22 |
|
23 | 23 | def register_storage( |
@@ -49,31 +49,26 @@ def create_storage(config: StorageConfig) -> Storage: |
49 | 49 | The created storage implementation. |
50 | 50 | """ |
51 | 51 | config_model = config.model_dump() |
52 | | - storage_strategy = config_model.pop("type") |
53 | | - |
54 | | - # Check storage_strategy is a string |
55 | | - if not isinstance(storage_strategy, str): |
56 | | - msg = f"StorageConfig.type must be a string, got {type(storage_strategy)}" |
57 | | - raise TypeError(msg) |
| 52 | + storage_strategy = config.type |
58 | 53 |
|
59 | 54 | if storage_strategy not in storage_factory: |
60 | 55 | match storage_strategy: |
61 | | - case StorageType.FILE: |
| 56 | + case StorageType.File: |
62 | 57 | from graphrag_storage.file_storage import FileStorage |
63 | 58 |
|
64 | | - register_storage(StorageType.FILE, FileStorage) |
65 | | - case StorageType.MEMORY: |
| 59 | + register_storage(StorageType.File, FileStorage) |
| 60 | + case StorageType.Memory: |
66 | 61 | from graphrag_storage.memory_storage import MemoryStorage |
67 | 62 |
|
68 | | - register_storage(StorageType.MEMORY, MemoryStorage) |
69 | | - case StorageType.AZURE_BLOB: |
| 63 | + register_storage(StorageType.Memory, MemoryStorage) |
| 64 | + case StorageType.AzureBlob: |
70 | 65 | from graphrag_storage.azure_blob_storage import AzureBlobStorage |
71 | 66 |
|
72 | | - register_storage(StorageType.AZURE_BLOB, AzureBlobStorage) |
73 | | - case StorageType.AZURE_COSMOS: |
| 67 | + register_storage(StorageType.AzureBlob, AzureBlobStorage) |
| 68 | + case StorageType.AzureCosmos: |
74 | 69 | from graphrag_storage.azure_cosmos_storage import AzureCosmosStorage |
75 | 70 |
|
76 | | - register_storage(StorageType.AZURE_COSMOS, AzureCosmosStorage) |
| 71 | + register_storage(StorageType.AzureCosmos, AzureCosmosStorage) |
77 | 72 | case _: |
78 | 73 | msg = f"StorageConfig.type '{storage_strategy}' is not registered in the StorageFactory. Registered types: {', '.join(storage_factory.keys())}." |
79 | 74 | raise ValueError(msg) |
|
0 commit comments