core.orm.sql
Attributes
Functions
|
Takes a raw SQL query and turns it into a selectable SQLAlchemy |
|
|
|
|
|
Module Contents
- 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'))