pydantic_aioredis.model.AutoModel¶
- class pydantic_aioredis.model.AutoModel¶
Bases:
Model
A model that automatically saves to redis on creation and syncs changing fields to redis
- __init__(**data: Any) None ¶
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Methods
__init__
(**data)Create a new model by parsing and validating input data from keyword arguments.
construct
([_fields_set])Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
copy
(*[, include, exclude, update, deep])Duplicate a model, optionally choose which fields to include, exclude and change.
delete
([ids])deletes a given row or sets of rows in the table
deserialize_partially
(data)Converts model fields back from json strings into python data types.
dict
(*[, include, exclude, by_alias, ...])Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
from_orm
(obj)Gets the protected _primary_key_field
Returns the key in which the primary keys of the given table have been saved
insert
(data[, life_span_seconds])Inserts a given row or sets of rows into the table
json
(*[, include, exclude, by_alias, ...])Generate a JSON representation of the model, include and exclude arguments as per dict().
json_default
(obj)JSON serializer for objects not serializable by default json library Currently handles: datetimes -> obj.isoformat, ipaddress and ipnetwork -> str
json_object_hook
(obj)Can be overridden to handle custom json -> object
parse_file
(path, *[, content_type, ...])parse_obj
(obj)parse_raw
(b, *[, content_type, encoding, ...])save
()schema
([by_alias, ref_template])schema_json
(*[, by_alias, ref_template])select
([columns, ids, skip, limit])Selects given rows or sets of rows in the table
serialize_partially
(data)Converts data types that are not compatible with Redis into json strings by looping through the models fields and inspecting its types.
set_auto_save
([auto_save])Change this instance of a model's _auto_save setting
set_auto_sync
([auto_sync])Change this instance of a model's _auto_sync setting
update
()Async Context manager to allow for updating multiple fields without syncing to redis until the end
update_forward_refs
(**localns)Try to update ForwardRefs on fields based on this Model, globalns and localns.
validate
(value)Attributes
auto_save
auto_sync
- class Config¶
Bases:
object
Pydantic schema config for _AbstractModel
- classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model ¶
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model ¶
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep – set to True to make a deep copy of the model
- Returns:
new model instance
- async classmethod delete(ids: Any | List[Any] | None = None) List[int] | None ¶
deletes a given row or sets of rows in the table
- classmethod deserialize_partially(data: Dict[bytes, Any])¶
Converts model fields back from json strings into python data types.
Users can override serialze paritally and deserialze partially
- dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny ¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- classmethod get_primary_key_field()¶
Gets the protected _primary_key_field
- classmethod get_table_index_key()¶
Returns the key in which the primary keys of the given table have been saved
- async classmethod insert(data: List[_AbstractModel] | _AbstractModel, life_span_seconds: int | None = None)¶
Inserts a given row or sets of rows into the table
- json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode ¶
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- classmethod json_default(obj: Any) str ¶
JSON serializer for objects not serializable by default json library Currently handles: datetimes -> obj.isoformat, ipaddress and ipnetwork -> str
- classmethod json_object_hook(obj: dict)¶
Can be overridden to handle custom json -> object
- async classmethod select(columns: List[str] | None = None, ids: List[Any] | None = None, skip: int | None = None, limit: int | None = None) List[Any] | None ¶
Selects given rows or sets of rows in the table
- Pagination is accomplished by using the below variables
skip: Optional[int] limit: Optional[int]
- classmethod serialize_partially(data: Dict[str, Any])¶
Converts data types that are not compatible with Redis into json strings by looping through the models fields and inspecting its types.
str, float, int - will be stored in redis as a string field None - will be converted to the string “None” More complex data types will be json dumped.
The json dumper uses class.json_default as its default serializer. Users can override json_default with a custom json serializer if they chose to. Users can override serialze paritally and deserialze partially
- set_auto_save(auto_save: bool = True) None ¶
Change this instance of a model’s _auto_save setting
- set_auto_sync(auto_sync: bool = True) None ¶
Change this instance of a model’s _auto_sync setting
- update()¶
Async Context manager to allow for updating multiple fields without syncing to redis until the end
- classmethod update_forward_refs(**localns: Any) None ¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.