Skip to content

SQL API

SQLEntity

Bases: EntityVisibility, SQLModel, HasOrm[Mapped[Any]], Entitieable[IDT], Generic[IDT]

__table__ class-attribute

__table__: Table

__signpost__ class-attribute

__signpost__: SQLSignpost

id instance-attribute

id: Field[IDT]

SQLEntityStream

Bases: SimpleAsyncEntityStream[E], AsyncEntityStream[E], SQLDataBackend

Entity stream backed by a SQLAlchemy Select.

Operations that SQL can express are pushed down into the statement (take → LIMIT, drop → OFFSET, sort by field → ORDER BY, distinct, count, first, column projection via to_values). Everything else (Python predicates/mappers) falls back to the in-memory stream over a server-side cursor — rows are never fully buffered.

__init__

__init__(
    stmt: Select[tuple[E]],
    signpost: SQLSignpost
    | Signpostable[AbstractAsyncContextManager[AsyncSession]],
) -> None

__aiter__

__aiter__() -> AsyncIterator[E]

take

take(n: int) -> SQLEntityStream[E]

drop

drop(n: int) -> SQLEntityStream[E]

distinct

distinct() -> SQLEntityStream[E]

sort

sort[R: RichComparisonable[Any]](
    key: GetterCallable[E, R], reverse: bool = False
) -> AsyncEntityStream[E]

count async

count() -> int

first async

first() -> E | None

to_values

to_values[K: HashableAndValuable](
    mapper: MapperCallable[E, K],
) -> AsyncValueStream[K]

SQLQuery dataclass

Bases: BaseQuery[E, Select[tuple[E]]]

__init__

__init__(entity: type[E], statement: StatementT | None = None) -> None

SQLValueStream

Bases: SimpleAsyncValueStream[T], AsyncValueStream[T], SQLDataBackend

Single-column stream backed by a SQLAlchemy Select.

Pushes down take/drop/distinct/sort and the aggregate terminals (count, sum, min, max) into SQL; Python callables fall back to the in-memory stream over a server-side cursor.

__init__

__init__(
    stmt: Select[tuple[T]],
    signpost: SQLSignpost
    | Signpostable[AbstractAsyncContextManager[AsyncSession]],
) -> None

__aiter__

__aiter__() -> AsyncIterator[T]

take

take(n: int) -> SQLValueStream[T]

drop

drop(n: int) -> SQLValueStream[T]

distinct

distinct() -> SQLValueStream[T]

sort

sort[R: RichComparisonable](
    key: GetterCallable[T, R] | None = None, reverse: bool = False
) -> AsyncValueStream[T]

count async

count() -> int

first async

first() -> T | None

sum async

sum() -> T | None

min async

min[K: RichComparisonable](
    key: GetterCallable[T, K] | None = None,
) -> T | None

max async

max[K: RichComparisonable](
    key: GetterCallable[T, K] | None = None,
) -> T | None