MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / lambda_stmt

Function lambda_stmt

lib/sqlalchemy/sql/lambdas.py:80–150  ·  view source on GitHub ↗

Produce a SQL statement that is cached as a lambda. The Python code object within the lambda is scanned for both Python literals that will become bound parameters as well as closure variables that refer to Core or ORM constructs that may vary. The lambda itself will be invoked onl

(
    lmb: _StmtLambdaType,
    enable_tracking: bool = True,
    track_closure_variables: bool = True,
    track_on: Optional[object] = None,
    global_track_bound_values: bool = True,
    track_bound_values: bool = True,
    lambda_cache: Optional[_LambdaCacheType] = None,
)

Source from the content-addressed store, hash-verified

78
79
80def lambda_stmt(
81 lmb: _StmtLambdaType,
82 enable_tracking: bool = True,
83 track_closure_variables: bool = True,
84 track_on: Optional[object] = None,
85 global_track_bound_values: bool = True,
86 track_bound_values: bool = True,
87 lambda_cache: Optional[_LambdaCacheType] = None,
88) -> StatementLambdaElement:
89 """Produce a SQL statement that is cached as a lambda.
90
91 The Python code object within the lambda is scanned for both Python
92 literals that will become bound parameters as well as closure variables
93 that refer to Core or ORM constructs that may vary. The lambda itself
94 will be invoked only once per particular set of constructs detected.
95
96 E.g.::
97
98 from sqlalchemy import lambda_stmt
99
100 stmt = lambda_stmt(lambda: table.select())
101 stmt += lambda s: s.where(table.c.id == 5)
102
103 result = connection.execute(stmt)
104
105 The object returned is an instance of :class:`_sql.StatementLambdaElement`.
106
107 .. versionadded:: 1.4
108
109 :param lmb: a Python function, typically a lambda, which takes no arguments
110 and returns a SQL expression construct
111 :param enable_tracking: when False, all scanning of the given lambda for
112 changes in closure variables or bound parameters is disabled. Use for
113 a lambda that produces the identical results in all cases with no
114 parameterization.
115 :param track_closure_variables: when False, changes in closure variables
116 within the lambda will not be scanned. Use for a lambda where the
117 state of its closure variables will never change the SQL structure
118 returned by the lambda.
119 :param track_bound_values: when False, bound parameter tracking will
120 be disabled for the given lambda. Use for a lambda that either does
121 not produce any bound values, or where the initial bound values never
122 change.
123 :param global_track_bound_values: when False, bound parameter tracking
124 will be disabled for the entire statement including additional links
125 added via the :meth:`_sql.StatementLambdaElement.add_criteria` method.
126 :param lambda_cache: a dictionary or other mapping-like object where
127 information about the lambda's Python code as well as the tracked closure
128 variables in the lambda itself will be stored. Defaults
129 to a global LRU cache. This cache is independent of the "compiled_cache"
130 used by the :class:`_engine.Connection` object.
131
132 .. seealso::
133
134 :ref:`engine_lambda_caching`
135
136
137 """

Callers 13

sevenMethod · 0.90
run_my_statementMethod · 0.90
test_9029_integrationMethod · 0.90
goMethod · 0.90
insMethod · 0.90
updMethod · 0.90
lambda_stmt.pyFile · 0.90
queryMethod · 0.90
goMethod · 0.90

Calls 2

LambdaOptionsClass · 0.85

Tested by 12

sevenMethod · 0.72
run_my_statementMethod · 0.72
test_9029_integrationMethod · 0.72
goMethod · 0.72
insMethod · 0.72
updMethod · 0.72
queryMethod · 0.72
goMethod · 0.72