actions
FilterAction
Bases: QueryAction
Represents a single WHERE predicate on a queryset.
Created for each key=value (or key__op=value) passed to
filter(...) / exclude(...) and to filtering shortcuts like
get(...) / first(...).
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
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 106 107 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 133 134 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 160 161 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 | |
binds_slot()
Return whether the value is bound as a parameter: SQLAlchemy renders
None (IS NULL), booleans and isnull checks into the SQL text.
Only values that are bound can get a named slot in a statement
template. The others stay in the SQL text and become part of the
template's cache key instead (see templates.value_cache_key)::
| Text Only | |
|---|---|
1 2 | |
Returns:
| Type | Description |
|---|---|
bool
|
True when the value is sent as a bound parameter |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
bound_value()
Return the value bound to the query: an ormar Model is replaced by its
value it is referenced by (its primary key or the foreign key's
to_field), so filter(author=author) binds author.pk.
filter_value itself is left untouched, so the action can be read
again on every call to collect the value for a cached template.
Returns:
| Type | Description |
|---|---|
Any
|
value to bind |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_text_clause(binder=None)
Escapes characters if it's required. Substitutes values of the models if value is a ormar Model with its pk value. Compiles the clause.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binder
|
Optional[SlotBinder]
|
names the bound value for statement templates
( |
None
|
Returns:
| Type | Description |
|---|---|
sqlalchemy.sql.elements.TextClause
|
complied and escaped clause |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
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 | |
has_escaped_characters()
Check if value is a string that contains characters to escape
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
126 127 128 129 130 | |
path_actions()
Returns:
| Type | Description |
|---|---|
list[QueryAction]
|
the action and the fields its expression reads, each resolving one relation path to a joined table |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
103 104 105 106 107 108 109 | |
update_select_related(select_related)
Add the joins of the filtered field and of the fields its expression
reads (see QueryAction.update_select_related).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
select_related
|
list[str]
|
list of relation join strings |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list of relation joins with implied joins from filter added |
Source code in ormar/queryset/actions/filter_action.py
| Python | |
|---|---|
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
OrderAction
Bases: QueryAction
Represents a single ORDER BY directive on a queryset.
Created when order_by(...) or Field.asc() / Field.desc() is
used, and internally to apply the default primary-key ordering.
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 106 107 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 133 134 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 160 161 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 | |
field_aliases
property
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
columns the field is ordered by: its column, or every column of a foreign key stored in several columns |
check_if_filter_apply(target_model, alias)
Checks filter conditions to find if they apply to current join.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_model
|
type[Model]
|
model which is now processed |
required |
alias
|
str
|
prefix of the relation |
required |
Returns:
| Type | Description |
|---|---|
bool
|
result of the check |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
192 193 194 195 196 197 198 199 200 201 202 203 | |
flipped()
Returns a shallow copy of this order action with the sort direction
and any NULLS FIRST/NULLS LAST annotation inverted.
Used by reverse slicing to turn an ASC/DESC ordering into its mirror
image so that LIMIT N fetches rows from the tail of the original
ordering. Callers are responsible for reversing the result list in
memory afterwards so the caller-visible ordering is preserved.
Returns:
| Type | Description |
|---|---|
OrderAction
|
new OrderAction with flipped direction and nulls ordering |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
from_model_defaults(model_cls)
classmethod
Builds the default list of OrderAction instances from a model's
OrmarConfig.orders_by (which always contains at least the primary
key, populated by the metaclass).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_cls
|
type[Model]
|
model class whose defaults should be used |
required |
Returns:
| Type | Description |
|---|---|
list[OrderAction]
|
list of default OrderAction instances for the model |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
get_field_name_text()
Escapes characters if it's required. Substitutes values of the models if value is a ormar Model with its pk value. Compiles the clause.
Returns:
| Type | Description |
|---|---|
sqlalchemy.sql.elements.TextClause
|
complied and escaped clause |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
70 71 72 73 74 75 76 77 78 79 80 | |
get_min_or_max()
Used in limit sub queries where you need to use aggregated functions in order to order by columns not included in group by. For postgres bool field it's using bool_or function as aggregates does not work with this type of columns.
Returns:
| Type | Description |
|---|---|
sqlalchemy.sql.elements.TextClause
|
min or max function to order |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_text_clause()
Escapes characters if it's required. Substitutes values of the models if value is a ormar Model with its pk value. Compiles the clause.
Returns:
| Type | Description |
|---|---|
sqlalchemy.sql.elements.TextClause
|
complied and escaped clause |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
RandomOrder
Random order of the queried model, the ormar.random() form of
order_by("?").
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
248 249 250 251 252 253 254 255 | |
SelectAction
Bases: QueryAction
Represents a single column target for an aggregate function on a queryset.
Created when .min() / .max() / .sum() / .avg() is called,
optionally traversing relations via __. Also resolves the fields read
by column expressions (see expression_columns).
Source code in ormar/queryset/actions/select_action.py
| Python | |
|---|---|
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
random()
Order the rows randomly, same as "?"::
| Text Only | |
|---|---|
1 | |
Returns:
| Type | Description |
|---|---|
RandomOrder
|
random order to pass to |
Source code in ormar/queryset/actions/order_action.py
| Python | |
|---|---|
258 259 260 261 262 263 264 265 266 267 | |