core.orm.sql ============ .. py:module:: core.orm.sql Attributes ---------- .. autoapisummary:: core.orm.sql.NESTED_TYPE Functions --------- .. autoapisummary:: core.orm.sql.as_selectable core.orm.sql.type_by_string core.orm.sql.as_selectable_from_path core.orm.sql.column_names_with_comments Module Contents --------------- .. py:data:: NESTED_TYPE .. py:function:: as_selectable(query: str, alias: str | None = None) -> sqlalchemy.sql.selectable.Alias 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')) .. py:function:: type_by_string(expression: str) -> type[sqlalchemy.types.TypeEngine[Any]] | sqlalchemy.types.TypeEngine[Any] .. py:function:: as_selectable_from_path(path: str) -> sqlalchemy.sql.selectable.Alias .. py:function:: column_names_with_comments(statement: pglast.ast.RawStmt, query: str) -> collections.abc.Iterator[tuple[str, str]]