MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _get_select_comparisons

Function _get_select_comparisons

examples/sharding/asyncio.py:200–246  ·  view source on GitHub ↗

Search a Select or Query object for binary expressions. Returns expressions which match a Column against one or more literal values as a list of tuples of the form (column, operator, values). "values" is a single value or tuple of values depending on the operator.

(statement)

Source from the content-addressed store, hash-verified

198
199
200def _get_select_comparisons(statement):
201 """Search a Select or Query object for binary expressions.
202
203 Returns expressions which match a Column against one or more
204 literal values as a list of tuples of the form
205 (column, operator, values). "values" is a single value
206 or tuple of values depending on the operator.
207
208 """
209 binds = {}
210 clauses = set()
211 comparisons = []
212
213 def visit_bindparam(bind):
214 # visit a bind parameter.
215
216 value = bind.effective_value
217 binds[bind] = value
218
219 def visit_column(column):
220 clauses.add(column)
221
222 def visit_binary(binary):
223 if binary.left in clauses and binary.right in binds:
224 comparisons.append(
225 (binary.left, binary.operator, binds[binary.right])
226 )
227
228 elif binary.left in binds and binary.right in clauses:
229 comparisons.append(
230 (binary.right, binary.operator, binds[binary.left])
231 )
232
233 # here we will traverse through the query's criterion, searching
234 # for SQL constructs. We will place simple column comparisons
235 # into a list.
236 if statement.whereclause is not None:
237 visitors.traverse(
238 statement.whereclause,
239 {},
240 {
241 "bindparam": visit_bindparam,
242 "binary": visit_binary,
243 "column": visit_column,
244 },
245 )
246 return comparisons
247
248
249# further configure create_session to use these functions

Callers 1

execute_chooserFunction · 0.70

Calls 1

traverseMethod · 0.45

Tested by

no test coverage detected