File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 1+ import logging
2+ from typing import Optional , Type
3+
4+ from vectorcode .cli_utils import Config
5+ from vectorcode .database .base import DatabaseConnectorBase
6+
7+ logger = logging .getLogger (name = __name__ )
8+
9+
10+ def get_database_connector (config : Config ) -> DatabaseConnectorBase :
11+ """
12+ It's CRUCIAL to keep the `import`s of the database connectors in the branches.
13+ This allow them to be lazy-imported. This also allow us to keep the main package
14+ lightweight because we don't have to include dependencies for EVERY database.
15+
16+ """
17+ cls : Optional [Type [DatabaseConnectorBase ]] = None
18+
19+ match config .db_type :
20+ case "ChromaDB0Connector" :
21+ from vectorcode .database .chroma0 import ChromaDB0Connector
22+
23+ cls = ChromaDB0Connector
24+ case _:
25+ raise ValueError (f"Unrecognised database type: { config .db_type } " )
26+
27+ return cls .create (config )
Original file line number Diff line number Diff line change 11import logging
22
33from vectorcode .cli_utils import Config
4- from vectorcode .database . chroma0 import ChromaDB0Connector
4+ from vectorcode .database import get_database_connector
55from vectorcode .database .errors import CollectionNotFoundError
66
77logger = logging .getLogger (name = __name__ )
88
99
1010async def drop (config : Config ) -> int :
11- database = ChromaDB0Connector (config )
11+ database = get_database_connector (config )
1212 try :
1313 await database .drop (str (config .project_root ))
1414 if not config .pipe :
You can’t perform that action at this time.
0 commit comments