Skip to content

SqlAlchemyFetcher#

dbally.similarity.SqlAlchemyFetcher #

SqlAlchemyFetcher(sqlalchemy_engine: Engine)

Bases: SimilarityFetcher

Fetches the data from the database using SQLAlchemy.

Source code in src/dbally/similarity/sqlalchemy_base.py
def __init__(self, sqlalchemy_engine: sqlalchemy.engine.Engine) -> None:
    self.sqlalchemy_engine = sqlalchemy_engine

sqlalchemy_engine instance-attribute #

sqlalchemy_engine = sqlalchemy_engine

get_query abstractmethod #

get_query() -> Select

Returns query that will be used to fetch the data from the database. Should include a single text column.

RETURNS DESCRIPTION
Select

sqlalchemy.Select: The query to fetch the data.

Source code in src/dbally/similarity/sqlalchemy_base.py
@abc.abstractmethod
def get_query(self) -> sqlalchemy.Select:
    """
    Returns query that will be used to fetch the data from the database. Should include a single text column.

    Returns:
        sqlalchemy.Select: The query to fetch the data.
    """

fetch async #

fetch() -> List[str]

Fetches the data from the source and returns it as a list of strings.

RETURNS DESCRIPTION
List[str]

The fetched data.

Source code in src/dbally/similarity/sqlalchemy_base.py
async def fetch(self) -> List[str]:
    """
    Fetches the data from the source and returns it as a list of strings.

    Returns:
        The fetched data.
    """
    with self.sqlalchemy_engine.connect() as conn:
        result = conn.execute(self.get_query())
        return [row[0] for row in result]