Skip to content

FalkorDBClient

mdo_framework.db.client.FalkorDBClient

Singleton class to manage the connection to the FalkorDB database.

Source code in src/mdo_framework/db/client.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class FalkorDBClient:
    """Singleton class to manage the connection to the FalkorDB database."""

    _instance = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            cls._instance._initialize()
        return cls._instance

    def _initialize(self):
        """Initializes the FalkorDB connection."""
        host = os.getenv("FALKORDB_HOST", "localhost")
        port = int(os.getenv("FALKORDB_PORT", 6379))
        self.client = FalkorDB(host=host, port=port)
        self.graph_name = "mdo_graph"
        self.graph = self.client.select_graph(self.graph_name)

    def get_graph(self):
        """Returns the graph object for executing queries."""
        return self.graph

    def close(self):
        """Closes the connection."""

close()

Closes the connection.

Source code in src/mdo_framework/db/client.py
35
36
def close(self):
    """Closes the connection."""

get_graph()

Returns the graph object for executing queries.

Source code in src/mdo_framework/db/client.py
31
32
33
def get_graph(self):
    """Returns the graph object for executing queries."""
    return self.graph