NoSQLRunner

from mango.nosql_runner import NoSQLRunner

Abstract base class for all database backends. Implement this to add support for any NoSQL database.

Interface

class NoSQLRunner(ABC):

    @abstractmethod
    def connect(self, connection_string: str, **kwargs) -> None: ...

    @abstractmethod
    def execute_query(self, operation: QueryRequest) -> pd.DataFrame: ...

    @abstractmethod
    def introspect_schema(self) -> dict[str, SchemaInfo]: ...

    @abstractmethod
    def get_sample_documents(self, collection: str, n: int = 5) -> list[dict]: ...

    @abstractmethod
    def list_collections(self) -> list[str]: ...

    @abstractmethod
    def get_indexes(self, collection: str) -> list[dict]: ...

QueryRequest

@dataclass
class QueryRequest:
    operation: Literal["find", "aggregate", "count", "distinct"]
    collection: str
    filter: dict | None = None
    pipeline: list[dict] | None = None
    projection: dict | None = None
    sort: dict | None = None
    limit: int | None = None
    distinct_field: str | None = None

Exceptions

ExceptionWhen
BackendErrorConnection failure, collection not found, introspection error
QueryErrorDriver error during query execution
ValidationErrorOperation not allowed, missing required field

All inherit from MangoError.

Built-in implementation

ClassImport
MongoRunnermango.integrations.mongodb

Custom implementation

from mango.nosql_runner import NoSQLRunner
from mango.core.types import QueryRequest, SchemaInfo
import pandas as pd

class MyRedisRunner(NoSQLRunner):

    def connect(self, connection_string: str, **kwargs) -> None:
        self._client = redis.from_url(connection_string)

    def execute_query(self, operation: QueryRequest) -> pd.DataFrame:
        # Translate QueryRequest to Redis commands
        ...

    def list_collections(self) -> list[str]:
        # In Redis: return key patterns or namespaces
        ...

    # implement remaining methods...