Skip to content

sql

SqlLike = Union[Composable, IntoSql] module-attribute

SQL or a type convertible to SQL

IntoSql

Bases: Protocol

Type that has a SQL representation

__sql__()

Returns:

Source code in jinja_psycopg/sql.py
def __sql__(self) -> Composable:
    """
    Returns:
        SQL representation
    """
    ...

sql_filter(value)

Jinja filter for converting a string to raw SQL

Usage: {{ 'text' | sql }}

Source code in jinja_psycopg/sql.py
def sql_filter(value: str) -> SQL:
    """Jinja filter for converting a string to raw SQL

    Usage: `{{ 'text' | sql }}`
    """
    return SQL(value)

sql_join_filter(value, delimiter, attribute=None)

Similar to jinja's join filter, but for SQL

Parameters:

  • value (Iterable[SqlLike]) –

    sequence to join

  • delimiter (str) –

    join delimiter

  • attribute (Optional[str], default: None ) –

    extract objects' attribute,

    like {{ users|join(', ', attribute='username') }}

Source code in jinja_psycopg/sql.py
def sql_join_filter(
    value: Iterable[SqlLike], delimiter: str, attribute: Optional[str] = None
):
    """
    Similar to jinja's [join](https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.join)
        filter, but for SQL

    Args:
        value: sequence to join
        delimiter: join delimiter
        attribute: extract objects' attribute,

            like `{{ users|join(', ', attribute='username') }}`
    """
    return SQL(delimiter).join(_preprocess_before_join(value, attribute))