|
| 1 | +from nodestream.databases import DatabaseConnector, TypeRetriever |
| 2 | +from nodestream.databases.query_executor import QueryExecutor |
| 3 | +from nodestream.schema.migrations import Migrator |
| 4 | + |
| 5 | +from .ingest_query_builder import Neo4jIngestQueryBuilder |
| 6 | +from .migrator import Neo4jMigrator |
| 7 | +from .neo4j_database import Neo4jDatabaseConnection |
| 8 | +from .query_executor import Neo4jQueryExecutor |
| 9 | +from .type_retriever import Neo4jTypeRetriever |
| 10 | + |
| 11 | + |
| 12 | +class Neo4jDatabaseConnector(DatabaseConnector, alias="neo4j"): |
| 13 | + """A Connector for Neo4j Graph Databases. |
| 14 | +
|
| 15 | + This class is responsible for creating the various components needed for |
| 16 | + nodestream to interact with a Neo4j database. It is also responsible |
| 17 | + for providing the configuration options for the Neo4j database. |
| 18 | + """ |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def from_file_data( |
| 22 | + cls, |
| 23 | + use_enterprise_features: bool = False, |
| 24 | + use_apoc: bool = True, |
| 25 | + **connection_args |
| 26 | + ): |
| 27 | + database_connection = Neo4jDatabaseConnection.from_configuration( |
| 28 | + **connection_args |
| 29 | + ) |
| 30 | + return cls( |
| 31 | + database_connection=database_connection, |
| 32 | + use_enterprise_features=use_enterprise_features, |
| 33 | + use_apoc=use_apoc, |
| 34 | + ) |
| 35 | + |
| 36 | + def __init__( |
| 37 | + self, |
| 38 | + database_connection: Neo4jDatabaseConnection, |
| 39 | + use_apoc: bool, |
| 40 | + use_enterprise_features: bool, |
| 41 | + ) -> None: |
| 42 | + self.use_enterprise_features = use_enterprise_features |
| 43 | + self.use_apoc = use_apoc |
| 44 | + self.database_connection = database_connection |
| 45 | + |
| 46 | + def make_query_executor(self) -> QueryExecutor: |
| 47 | + query_builder = Neo4jIngestQueryBuilder(self.use_apoc) |
| 48 | + return Neo4jQueryExecutor(self.database_connection, query_builder) |
| 49 | + |
| 50 | + def make_type_retriever(self) -> TypeRetriever: |
| 51 | + return Neo4jTypeRetriever(self.database_connection) |
| 52 | + |
| 53 | + def make_migrator(self) -> Migrator: |
| 54 | + return Neo4jMigrator(self.database_connection, self.use_enterprise_features) |
0 commit comments