lumix.utils.orm.LXORMContext

class lumix.utils.orm.LXORMContext(session)[source]

Type-safe ORM query interface with generic support.

Provides a type-safe wrapper around ORM sessions that enables IDE autocomplete and type checking for database queries. The generic type parameter ensures that query results have proper type information.

Parameters:

session (Any)

session

The underlying ORM session (SQLAlchemy, Django, etc.)

Type Parameters:

TModel: The ORM model type being queried

Examples

Create context from SQLAlchemy session:

from sqlalchemy.orm import Session
from lumix.utils import LXORMContext

session = Session()
ctx = LXORMContext(session)

# Query with full type safety
products = ctx.query(Product).all()  # Type: List[Product]

Chain query operations:

expensive_products = (
    ctx.query(Product)
    .filter(lambda p: p.price > 100)
    .filter(lambda p: p.in_stock)
    .all()
)

See also

LXTypedQuery: The query builder returned by query()

__init__(session)[source]

Initialize ORM context with a session.

Parameters:

session (Any) – ORM session object (e.g., SQLAlchemy Session, Django QuerySet)

Examples

Initialize with SQLAlchemy session:

from sqlalchemy.orm import Session
session = Session()
ctx = LXORMContext(session)

Methods

__init__(session)

Initialize ORM context with a session.

query(model)

Start a type-safe query for the specified model.

__init__(session)[source]

Initialize ORM context with a session.

Parameters:

session (Any) – ORM session object (e.g., SQLAlchemy Session, Django QuerySet)

Examples

Initialize with SQLAlchemy session:

from sqlalchemy.orm import Session
session = Session()
ctx = LXORMContext(session)
query(model)[source]

Start a type-safe query for the specified model.

Parameters:

model (Type[TypeVar(TModel)]) – The ORM model class to query

Return type:

LXTypedQuery[TypeVar(TModel)]

Returns:

A type-safe query builder for the model

Examples

Basic query:

products = ctx.query(Product).all()

With filtering:

active_products = ctx.query(Product).filter(lambda p: p.active).all()