core.orm.sql

Attributes

NESTED_TYPE

Functions

as_selectable(→ sqlalchemy.sql.selectable.Alias)

Takes a raw SQL query and turns it into a selectable SQLAlchemy

type_by_string(→ type[TypeEngine[Any]] | TypeEngine[Any])

as_selectable_from_path(→ sqlalchemy.sql.selectable.Alias)

column_names_with_comments(→ Iterator[tuple[str, str]])

Module Contents

core.orm.sql.NESTED_TYPE[source]
core.orm.sql.as_selectable(query: str, alias: str | None = None) sqlalchemy.sql.selectable.Alias[source]

Takes a raw SQL query and turns it into a selectable SQLAlchemy expression using annotations in comments.

Expects to find a SELECT statement like this:

SELECT
    foo,  -- Text
    bar   -- Integer
FROM
    foobar

The so created selectable can be used by SQLAlchemy:

from sqlalchemy import select

query = as_selectable('''
    SELECT
        foo, -- Text
        bar  -- Integer
    FROM
        foobar
''')

session.execute(select(query.c).where(query.c.foo == 'bar'))
core.orm.sql.type_by_string(expression: str) type[TypeEngine[Any]] | TypeEngine[Any][source]
core.orm.sql.as_selectable_from_path(path: str) sqlalchemy.sql.selectable.Alias[source]
core.orm.sql.column_names_with_comments(statement: pglast.ast.RawStmt, query: str) Iterator[tuple[str, str]][source]