slots
Slots: named bind parameters that take the per-call values of a statement template.
While a template is built, SlotBinder puts slots in place of the values
(filters as ormar_p{n}, limit and offset as ormar_limit and
ormar_offset). Writes bind values as ormar_v{i} and the primary key as
ormar_pk. On every call the values are collected under the same names::
| Text Only | |
|---|---|
1 2 | |
SlotBinder
Turns per-call values of a read statement into named bind parameters while
the statement is built. A filter action's value is named ormar_p{n}
after its position among the canonical actions, limit and offset get fixed
names::
| Text Only | |
|---|---|
1 2 3 | |
Slots are looked up by action object, not by order of use, because one
action can be emitted twice: with select_related and a limit, the
filters go into the pagination subquery and the outer query, and both
copies bind the same ormar_p{n}, so one value fills both.
Passed down through Query, FilterQuery, LimitQuery and
OffsetQuery; without a binder they bind the plain values as before.
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
__init__(actions)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
List[FilterAction]
|
filter actions of the queryset in canonical order |
required |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
182 183 184 185 186 187 188 189 | |
bind(action, value)
Return the named bind parameter for a filter action's value.
The parameter is built the way SQLAlchemy builds the bind of
column <op> value: it is compared to the column's type, so the value
gets the column's bind processing (dates, JSON, enums and so on), and
an in filter is expanding, so it renders one placeholder per item of
the list it is given on each call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
FilterAction
|
filter action the value belongs to |
required |
value
|
Any
|
value to bind |
required |
Returns:
| Type | Description |
|---|---|
BindParameter
|
named bind parameter |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
bind_key_in(action, value, column_types)
Return the expanding bind parameter of a row-value IN over several
key columns, typed as a tuple of the column types so each part gets its
column's bind processing::
| Text Only | |
|---|---|
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
FilterAction
|
the key |
required |
value
|
Any
|
key values, one tuple of parts per key |
required |
column_types
|
List[Any]
|
types of the key columns, in key order |
required |
Returns:
| Type | Description |
|---|---|
BindParameter
|
named expanding bind parameter |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
limit(value)
Return the named bind parameter for a limit, typed as an integer like
the one SQLAlchemy creates for select.limit(10).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
limit value |
required |
Returns:
| Type | Description |
|---|---|
BindParameter
|
named bind parameter |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
244 245 246 247 248 249 250 251 252 253 254 255 256 | |
offset(value)
Return the named bind parameter for an offset, typed as an integer like
the one SQLAlchemy creates for select.offset(10).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
offset value |
required |
Returns:
| Type | Description |
|---|---|
BindParameter
|
named bind parameter |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
258 259 260 261 262 263 264 265 266 267 268 269 270 | |
canonical_actions(filter_clauses, exclude_clauses)
Return every filter action of a queryset in canonical order: filter clauses first, then exclude clauses, each in build order::
| Text Only | |
|---|---|
1 2 | |
SlotBinder (naming the slots while building) and template_params
(collecting values on every call) both use this list, so a value always
ends up in the slot built for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_clauses
|
List[Any]
|
queryset filter clauses |
required |
exclude_clauses
|
List[Any]
|
queryset exclude clauses |
required |
Returns:
| Type | Description |
|---|---|
List[FilterAction]
|
filter actions in canonical order |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
iter_actions(clauses)
Yield the filter actions of a clause list in the order their SQL is built:
a group's nested groups first, then its own actions (the order
FilterGroup.get_text_clause emits them in)::
| Text Only | |
|---|---|
1 2 | |
The order is the same for every queryset of one cache key, so an action's index here can name its slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clauses
|
List[Union[FilterAction, FilterGroup]]
|
filter actions and filter groups |
required |
Returns:
| Type | Description |
|---|---|
Iterator[FilterAction]
|
filter actions in build order |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
template_params(actions, limit, offset)
Collect the values a template binds for one call, keyed like the slots
SlotBinder names::
| Text Only | |
|---|---|
1 2 | |
Actions whose value is written into the SQL text (see
FilterAction.binds_slot) get no entry, but still use up their index,
so the names of the other slots do not depend on those values. The offset
is only bound when non-zero, matching OffsetQuery, which leaves out
OFFSET 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
List[FilterAction]
|
filter actions in canonical order |
required |
limit
|
Optional[int]
|
effective limit (applied when not None) |
required |
offset
|
Optional[int]
|
effective offset (applied when truthy) |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
values per slot name |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
value_binds(table, names)
Return named bind parameters for the written columns, ormar_v{i} in
the given column order, typed like their columns::
| Text Only | |
|---|---|
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
written table |
required |
names
|
Tuple[str, ...]
|
written column names, sorted |
required |
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
bind parameter per column |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
value_params(names, values)
Return the written values keyed by their bind parameter names, matching
value_binds for the same names::
| Text Only | |
|---|---|
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
Tuple[str, ...]
|
written column names, sorted |
required |
values
|
Mapping[str, Any]
|
written values by column name |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
values by bind parameter name |
Source code in ormar/queryset/templates/slots.py
| Python | |
|---|---|
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |