A SQL construct where the state is stored as an un-invoked lambda. The :class:`_sql.LambdaElement` is produced transparently whenever passing lambda expressions into SQL constructs, such as:: stmt = select(table).where(lambda: table.c.col == parameter) The :class:`_sql.LambdaE
| 152 | |
| 153 | |
| 154 | class LambdaElement(elements.ClauseElement): |
| 155 | """A SQL construct where the state is stored as an un-invoked lambda. |
| 156 | |
| 157 | The :class:`_sql.LambdaElement` is produced transparently whenever |
| 158 | passing lambda expressions into SQL constructs, such as:: |
| 159 | |
| 160 | stmt = select(table).where(lambda: table.c.col == parameter) |
| 161 | |
| 162 | The :class:`_sql.LambdaElement` is the base of the |
| 163 | :class:`_sql.StatementLambdaElement` which represents a full statement |
| 164 | within a lambda. |
| 165 | |
| 166 | .. versionadded:: 1.4 |
| 167 | |
| 168 | .. seealso:: |
| 169 | |
| 170 | :ref:`engine_lambda_caching` |
| 171 | |
| 172 | """ |
| 173 | |
| 174 | __visit_name__ = "lambda_element" |
| 175 | |
| 176 | _is_lambda_element = True |
| 177 | |
| 178 | _traverse_internals = [ |
| 179 | ("_resolved", visitors.InternalTraversal.dp_clauseelement) |
| 180 | ] |
| 181 | |
| 182 | _transforms: Tuple[_CloneCallableType, ...] = () |
| 183 | |
| 184 | _resolved_bindparams: List[BindParameter[Any]] |
| 185 | parent_lambda: Optional[StatementLambdaElement] = None |
| 186 | closure_cache_key: Union[Tuple[Any, ...], Literal[CacheConst.NO_CACHE]] |
| 187 | role: Type[SQLRole] |
| 188 | _rec: Union[AnalyzedFunction, NonAnalyzedFunction] |
| 189 | fn: _AnyLambdaType |
| 190 | tracker_key: Tuple[CodeType, ...] |
| 191 | |
| 192 | def __repr__(self): |
| 193 | return "%s(%r)" % ( |
| 194 | self.__class__.__name__, |
| 195 | self.fn.__code__, |
| 196 | ) |
| 197 | |
| 198 | def __init__( |
| 199 | self, |
| 200 | fn: _LambdaType, |
| 201 | role: Type[SQLRole], |
| 202 | opts: Union[Type[LambdaOptions], LambdaOptions] = LambdaOptions, |
| 203 | apply_propagate_attrs: Optional[ClauseElement] = None, |
| 204 | ): |
| 205 | self.fn = fn |
| 206 | self.role = role |
| 207 | self.tracker_key = (fn.__code__,) |
| 208 | self.opts = opts |
| 209 | |
| 210 | if apply_propagate_attrs is None and (role is roles.StatementRole): |
| 211 | apply_propagate_attrs = self |