Skip to content

API Reference

Modeling

These are used for defining queries.

altqq.Query

Base class for query definitions.

This class can be inherited instead of providing the QueryMeta as the class metaclass.

Source code in src/altqq/structs.py
Python
class Query(metaclass=QueryMeta):
    """Base class for query definitions.

    This class can be inherited instead of providing the `QueryMeta` as the
    class metaclass.
    """

    __query__: ClassVar[str]

altqq.NonParameter

Non-parameter type hint.

altqq.ListParameter

List parameter type hint.

altqq.Calculated

Calculated value assignment.

PyODBC

These are used for working with PyODBC.

altqq.to_pyodbc(query)

Converts a Query to its corresponding PyODBCQuery object.

Parameters:

Name Type Description Default
query Query

Query to translate to PyODBC

required

Returns:

Name Type Description
PyODBCQuery PyODBCQuery

Equivalent query for PyODBC usage.

Source code in src/altqq/__init__.py
Python
def to_pyodbc(query: Query) -> PyODBCQuery:
    """Converts a `Query` to its corresponding `PyODBCQuery` object.

    Args:
        query (Query): Query to translate to PyODBC

    Returns:
        PyODBCQuery: Equivalent query for PyODBC usage.
    """
    return Translators.PYODBC(query)

altqq.PyODBCQuery dataclass

Converted Query object for PyODBC usage.

Source code in src/altqq/translators/pyodbc.py
Python
@dc.dataclass
class PyODBCQuery:
    """Converted `Query` object for PyODBC usage."""

    query: str
    parameters: Iterable[Any]

Psycopg

These are used for working with Psycopg.

altqq.to_psycopg(query)

Converts a Query to its corresponding PsycopgQuery object.

Parameters:

Name Type Description Default
query Query

Query to translate to Psycopg

required

Returns:

Name Type Description
PsycopgQuery PsycopgQuery

Equivalent query for Psycopg usage.

Source code in src/altqq/__init__.py
Python
def to_psycopg(query: Query) -> PsycopgQuery:
    """Converts a `Query` to its corresponding `PsycopgQuery` object.

    Args:
        query (Query): Query to translate to Psycopg

    Returns:
        PsycopgQuery: Equivalent query for Psycopg usage.
    """
    return Translators.PSYCOPG(query)

altqq.PsycopgQuery dataclass

Converted Query object for Psycopg usage.

Source code in src/altqq/translators/psycopg.py
Python
@dc.dataclass
class PsycopgQuery:
    """Converted `Query` object for Psycopg usage."""

    query: str
    parameters: Tuple[Any, ...]

Plain Text

These are used for working with plain text SQL.

altqq.to_plain_text(query)

Converts a Query to a plain text SQL.

The conversion to plain text also handles some of the data types. None is converted to NULL, numeric values are written as they are and string values and other object types are escaped using '.

Parameters:

Name Type Description Default
query Query

Query to convert.

required

Returns:

Name Type Description
str str

Query as plain text.

Source code in src/altqq/__init__.py
Python
def to_plain_text(query: Query) -> str:
    """Converts a `Query` to a plain text SQL.

    The conversion to plain text also handles some of the data types. None
    is converted to `NULL`, numeric values are written as they are and
    string values and other object types are escaped using `'`.

    Args:
        query (Query): Query to convert.

    Returns:
        str: Query as plain text.
    """
    return Translators.PLAIN_TEXT(query)