ReflectModel
class¶
saffier.ReflectModel
¶
ReflectModel(**kwargs)
Bases: Model
, SaffierBaseReflectModel
Reflect on async engines is not yet supported, therefore, we need to make a sync_engine call.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in saffier/core/db/models/base.py
38 39 |
|
Meta
¶
The Meta
class used to configure each metadata of the model.
Abstract classes are not generated in the database, instead, they are simply used as
a reference for field generation.
Usage:
.. code-block:: python3
class User(Model):
...
class Meta:
registry = models
tablename = "users"
declarative
classmethod
¶
declarative()
Source code in saffier/core/db/models/mixins/generics.py
13 14 15 |
|
generate_model_declarative
classmethod
¶
generate_model_declarative()
Transforms a core Saffier table into a Declarative model table.
Source code in saffier/core/db/models/mixins/generics.py
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 |
|
_update_auto_now_fields
¶
_update_auto_now_fields(values, fields)
Updates the auto fields
PARAMETER | DESCRIPTION |
---|---|
values |
TYPE:
|
fields |
TYPE:
|
Source code in saffier/core/utils/models.py
26 27 28 29 30 31 32 33 |
|
_resolve_value
¶
_resolve_value(value)
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE:
|
Source code in saffier/core/utils/models.py
35 36 37 38 39 40 41 42 43 |
|
setup_model_fields_from_kwargs
¶
setup_model_fields_from_kwargs(kwargs)
Loops and setup the kwargs of the model
PARAMETER | DESCRIPTION |
---|---|
kwargs |
TYPE:
|
Source code in saffier/core/db/models/base.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_instance_name
¶
get_instance_name()
Returns the name of the class in lowercase.
Source code in saffier/core/db/models/base.py
101 102 103 104 105 |
|
generate_proxy_model
classmethod
¶
generate_proxy_model()
Generates a proxy model for each model. This proxy model is a simple shallow copy of the original model being generated.
Source code in saffier/core/db/models/base.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
build
classmethod
¶
build(schema=None)
The inspect is done in an async manner and reflects the objects from the database.
PARAMETER | DESCRIPTION |
---|---|
schema |
TYPE:
|
Source code in saffier/core/db/models/base.py
244 245 246 247 248 249 250 251 252 |
|
_get_unique_constraints
classmethod
¶
_get_unique_constraints(columns)
Returns the unique constraints for the model.
The columns must be a a list, tuple of strings or a UniqueConstraint object.
PARAMETER | DESCRIPTION |
---|---|
columns |
TYPE:
|
Source code in saffier/core/db/models/base.py
162 163 164 165 166 167 168 169 170 171 172 173 |
|
_get_indexes
classmethod
¶
_get_indexes(index)
Creates the index based on the Index fields
PARAMETER | DESCRIPTION |
---|---|
index |
TYPE:
|
Source code in saffier/core/db/models/base.py
175 176 177 178 179 180 |
|
update_from_dict
¶
update_from_dict(dict_values)
Updates the current model object with the new fields
PARAMETER | DESCRIPTION |
---|---|
dict_values |
TYPE:
|
Source code in saffier/core/db/models/base.py
182 183 184 185 186 |
|
extract_db_fields
¶
extract_db_fields()
Extacts all the db fields and excludes the related_names since those are simply relations.
Source code in saffier/core/db/models/base.py
188 189 190 191 192 193 194 |
|
__setattr__
¶
__setattr__(key, value)
PARAMETER | DESCRIPTION |
---|---|
key |
TYPE:
|
value |
TYPE:
|
Source code in saffier/core/db/models/base.py
196 197 198 199 200 201 202 203 204 205 206 |
|
__get_instance_values
¶
__get_instance_values(instance)
PARAMETER | DESCRIPTION |
---|---|
instance |
TYPE:
|
Source code in saffier/core/db/models/base.py
208 209 210 211 212 213 |
|
__eq__
¶
__eq__(other)
PARAMETER | DESCRIPTION |
---|---|
other |
TYPE:
|
Source code in saffier/core/db/models/base.py
215 216 217 218 219 220 221 222 |
|
get_engine
cached
classmethod
¶
get_engine(url)
PARAMETER | DESCRIPTION |
---|---|
url |
TYPE:
|
Source code in saffier/core/db/models/base.py
231 232 233 234 |
|
reflect
classmethod
¶
reflect(tablename, metadata)
PARAMETER | DESCRIPTION |
---|---|
tablename |
TYPE:
|
metadata |
TYPE:
|
Source code in saffier/core/db/models/base.py
254 255 256 257 258 259 260 261 262 263 |
|
from_query_result
classmethod
¶
from_query_result(row, select_related=None, prefetch_related=None, is_only_fields=False, only_fields=None, is_defer_fields=False, exclude_secrets=False, using_schema=None)
Class method to convert a SQLAlchemy Row result into a SaffierModel row type.
Looping through select_related fields if the query comes from a select_related operation. Validates if exists the select_related and related_field inside the models.
When select_related and related_field exist for the same field being validated, the related field is ignored as it won't override the value already collected from the select_related.
If there is no select_related, then goes through the related field where it should only return the instance of the the ForeignKey with the ID, making it lazy loaded.
:return: Model class.
PARAMETER | DESCRIPTION |
---|---|
row |
TYPE:
|
select_related |
TYPE:
|
prefetch_related |
TYPE:
|
is_only_fields |
TYPE:
|
only_fields |
TYPE:
|
is_defer_fields |
TYPE:
|
exclude_secrets |
TYPE:
|
using_schema |
TYPE:
|
Source code in saffier/core/db/models/row.py
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 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 |
|
__apply_schema
classmethod
¶
__apply_schema(model, schema=None)
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
schema |
TYPE:
|
Source code in saffier/core/db/models/row.py
160 161 162 163 164 165 |
|
__should_ignore_related_name
classmethod
¶
__should_ignore_related_name(related_name, select_related)
Validates if it should populate the related field if select related is not considered.
PARAMETER | DESCRIPTION |
---|---|
related_name |
TYPE:
|
select_related |
TYPE:
|
Source code in saffier/core/db/models/row.py
167 168 169 170 171 172 173 174 175 176 177 178 |
|
__handle_prefetch_related
classmethod
¶
__handle_prefetch_related(row, model, prefetch_related, parent_cls=None, original_prefetch=None, is_nested=False)
Handles any prefetch related scenario from the model. Loads in advance all the models needed for a specific record
Recursively checks for the related field and validates if there is any conflicting
attribute. If there is, a QuerySetError
is raised.
PARAMETER | DESCRIPTION |
---|---|
row |
TYPE:
|
model |
TYPE:
|
prefetch_related |
TYPE:
|
parent_cls |
TYPE:
|
original_prefetch |
TYPE:
|
is_nested |
TYPE:
|
Source code in saffier/core/db/models/row.py
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 |
|
__process_nested_prefetch_related
classmethod
¶
__process_nested_prefetch_related(row, prefetch_related, parent_cls, original_prefetch, queryset)
Processes the nested prefetch related names.
PARAMETER | DESCRIPTION |
---|---|
row |
TYPE:
|
prefetch_related |
TYPE:
|
parent_cls |
TYPE:
|
original_prefetch |
TYPE:
|
queryset |
TYPE:
|
Source code in saffier/core/db/models/row.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
__run_query
async
classmethod
¶
__run_query(model=None, extra=None, queryset=None)
Runs a specific query against a given model with filters.
PARAMETER | DESCRIPTION |
---|---|
model |
TYPE:
|
extra |
TYPE:
|
queryset |
TYPE:
|
Source code in saffier/core/db/models/row.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
model_dump
¶
model_dump(include=None, exclude=None, exclude_none=False)
Dumps the model in a dict format.
PARAMETER | DESCRIPTION |
---|---|
include |
TYPE:
|
exclude |
TYPE:
|
exclude_none |
TYPE:
|
Source code in saffier/core/db/models/model.py
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 |
|
update
async
¶
update(**kwargs)
Update operation of the database fields.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in saffier/core/db/models/model.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
delete
async
¶
delete()
Delete operation from the database
Source code in saffier/core/db/models/model.py
91 92 93 94 95 96 97 98 99 |
|
load
async
¶
load()
Source code in saffier/core/db/models/model.py
101 102 103 104 105 106 107 108 109 110 111 |
|
_save
async
¶
_save(**kwargs)
Performs the save instruction.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
TYPE:
|
Source code in saffier/core/db/models/model.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
save
async
¶
save(force_save=False, values=None, **kwargs)
Performs a save of a given model instance. When creating a user it will make sure it can update existing or create a new one.
PARAMETER | DESCRIPTION |
---|---|
force_save |
TYPE:
|
values |
TYPE:
|
**kwargs |
TYPE:
|
Source code in saffier/core/db/models/model.py
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 |
|
__getattr__
¶
__getattr__(name)
Run an one off query to populate any foreign key making sure it runs only once per foreign key avoiding multiple database calls.
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
Source code in saffier/core/db/models/model.py
178 179 180 181 182 183 184 185 186 |
|