MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / StatementLambdaElement

Class StatementLambdaElement

lib/sqlalchemy/sql/lambdas.py:501–651  ·  view source on GitHub ↗

Represent a composable SQL statement as a :class:`_sql.LambdaElement`. The :class:`_sql.StatementLambdaElement` is constructed using the :func:`_sql.lambda_stmt` function:: from sqlalchemy import lambda_stmt stmt = lambda_stmt(lambda: select(table)) Once constructed,

Source from the content-addressed store, hash-verified

499
500
501class StatementLambdaElement(
502 roles.AllowsLambdaRole, ExecutableStatement, LambdaElement
503):
504 """Represent a composable SQL statement as a :class:`_sql.LambdaElement`.
505
506 The :class:`_sql.StatementLambdaElement` is constructed using the
507 :func:`_sql.lambda_stmt` function::
508
509
510 from sqlalchemy import lambda_stmt
511
512 stmt = lambda_stmt(lambda: select(table))
513
514 Once constructed, additional criteria can be built onto the statement
515 by adding subsequent lambdas, which accept the existing statement
516 object as a single parameter::
517
518 stmt += lambda s: s.where(table.c.col == parameter)
519
520 .. versionadded:: 1.4
521
522 .. seealso::
523
524 :ref:`engine_lambda_caching`
525
526 """
527
528 if TYPE_CHECKING:
529
530 def __init__(
531 self,
532 fn: _StmtLambdaType,
533 role: Type[SQLRole],
534 opts: Union[Type[LambdaOptions], LambdaOptions] = LambdaOptions,
535 apply_propagate_attrs: Optional[ClauseElement] = None,
536 ): ...
537
538 def __add__(
539 self, other: _StmtLambdaElementType[Any]
540 ) -> StatementLambdaElement:
541 return self.add_criteria(other)
542
543 def add_criteria(
544 self,
545 other: _StmtLambdaElementType[Any],
546 enable_tracking: bool = True,
547 track_on: Optional[Any] = None,
548 track_closure_variables: bool = True,
549 track_bound_values: bool = True,
550 ) -> StatementLambdaElement:
551 """Add new criteria to this :class:`_sql.StatementLambdaElement`.
552
553 E.g.::
554
555 >>> def my_stmt(parameter):
556 ... stmt = lambda_stmt(
557 ... lambda: select(table.c.x, table.c.y),
558 ... )

Callers 1

lambda_stmtFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected