diff --git a/app/core/neo4j_connection.py b/app/core/neo4j_connection.py new file mode 100644 index 0000000..597989d --- /dev/null +++ b/app/core/neo4j_connection.py @@ -0,0 +1,28 @@ +"""Neo4j driver singleton for health checks and graph queries.""" +from __future__ import annotations + +import logging +import os + +log = logging.getLogger(__name__) +_driver = None + + +def _init() -> None: + global _driver + if _driver is not None: + return + try: + from neo4j import GraphDatabase, basic_auth + + uri = os.getenv("NEO4J_URI", "bolt://rmi-neo4j:7687") + user = os.getenv("NEO4J_USER", "neo4j") + password = os.getenv("NEO4J_PASSWORD", "password") + _driver = GraphDatabase.driver(uri, auth=basic_auth(user, password)) + log.info("neo4j_driver_connected") + except Exception as exc: + log.warning("neo4j_driver_init_failed err=%s", exc) + _driver = None + + +_init()