utils
check_node_not_dict_or_not_last_node(part, is_last, current_level)
Checks if given name is not present in the current level of the structure. Checks if given name is not the last name in the split list of parts. Checks if the given name in current level is not a dictionary.
All those checks verify if there is a need for deeper traversal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
part |
str
|
|
required |
is_last |
bool
|
flag to check if last element |
required |
current_level |
Any
|
current level of the traversed structure |
required |
Returns:
Type | Description |
---|---|
bool
|
result of the check |
Source code in ormar\queryset\utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
convert_set_to_required_dict(set_to_convert)
Converts set to dictionary of required keys. Required key is Ellipsis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set_to_convert |
set
|
set to convert to dict |
required |
Returns:
Type | Description |
---|---|
Dict
|
set converted to dict of ellipsis |
Source code in ormar\queryset\utils.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
get_relationship_alias_model_and_str(source_model, related_parts)
Walks the relation to retrieve the actual model on which the clause should be constructed, extracts alias based on last relation leading to target model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
related_parts |
List
|
list of related names extracted from string |
required |
source_model |
Type[Model]
|
model from which relation starts |
required |
Returns:
Type | Description |
---|---|
Tuple[str, Type["Model"], str]
|
table prefix, target model and relation string |
Source code in ormar\queryset\utils.py
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 |
|
subtract_dict(current_dict, updating_dict)
Update one dict with another but with regard for nested keys.
That way nested sets are unionised, dicts updated and only other values are overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_dict |
Any
|
dict to update |
required |
updating_dict |
Any
|
dict with values to update |
required |
Returns:
Type | Description |
---|---|
Dict
|
combination of both dicts |
Source code in ormar\queryset\utils.py
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 |
|
translate_list_to_dict(list_to_trans, default=...)
Splits the list of strings by '__' and converts them to dictionary with nested models grouped by parent model. That way each model appears only once in the whole dictionary and children are grouped under parent name.
Default required key ise Ellipsis like in pydantic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_to_trans |
Union[List, Set]
|
input list |
required |
default |
Any
|
value to use as a default value |
...
|
is_order |
bool
|
flag if change affects order_by clauses are they require special default value with sort order. |
required |
Returns:
Type | Description |
---|---|
Dict
|
converted to dictionary input list |
Source code in ormar\queryset\utils.py
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 |
|
update(current_dict, updating_dict)
Update one dict with another but with regard for nested keys.
That way nested sets are unionised, dicts updated and only other values are overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_dict |
Any
|
dict to update |
required |
updating_dict |
Any
|
dict with values to update |
required |
Returns:
Type | Description |
---|---|
Dict
|
combination of both dicts |
Source code in ormar\queryset\utils.py
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 |
|
update_dict_from_list(curr_dict, list_to_update)
Converts the list into dictionary and later performs special update, where nested keys that are sets or dicts are combined and not overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curr_dict |
Dict
|
dict to update |
required |
list_to_update |
Union[List, Set]
|
list with values to update the dict |
required |
Returns:
Type | Description |
---|---|
Dict
|
updated dict |
Source code in ormar\queryset\utils.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|