Generic proxies
These proxies are generic. They can be used regardless of the type of source and destination.
Rename
- pydantic model crudcreator.proxy.proxy.Rename.Rename[source]
Proxy that changes entity field names. Also changes the entity name.
Example of descriptor, which changes the name of the interface on the destination side to “my_entity”, and the field name “column_1” to “field_1” on the destination side:
{ "name": "Rename", "params": { "interface_name": "my_entity", "translation_list": [ { "source": "column_1", "destination": "field_1" } ] } }
- field params: RenameParams [Required][source]
Rename proxy settings.
- async create(
- params: CreateParams,
Change column names from destination to source, then call the next proxy.
- Parameters:
params (CreateParams) –
- async delete(
- params: DeleteParams,
Change ids from destination to source, then call the next proxy.
- Parameters:
params (DeleteParams) –
- async read(
- params: ReadParams,
Changes filter names from destination to source. Changes the name of columns to be read from destination to source. Calls the next proxy. Then changes the name of the result columns from source to destination.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- async update(
- params: UpdateParams,
Changes column names and ids from destination to source, then calls the next proxy.
- Parameters:
params (UpdateParams) –
- pydantic model crudcreator.proxy.proxy.Rename.RenameParams[source]
Rename proxy settings.
- Validators:
unique_value
»translation_list
- field translation_list: list[Translation] [Required][source]
List of changes to be made.
- Validated by:
unique_value
- RenameParams.unique_value[source]
Checks that each field has a unique name, both on the source and destination sides.
- Parameters:
translation_list (list[Translation]) –
- Return type:
list[Translation]
RecastType
- pydantic model crudcreator.proxy.proxy.type.RecastType.RecastType[source]
Changes the type of a field and reprocesses it to match the new type.
Example of descriptor, which changes the type of the “field_bool_converted” field, which is a str at source, and becomes a boolean at destination.
{ "name": "RecastType", "params": { "list_recast_field": [ { "field_name": "field_bool_converted", "special_type": "$oui_non_type$" } ] } }
With “yes_no_type” defined as follows:
def oui_non_to_bool(v: str): if v == "oui": return True elif v == "non": return False elif v == None: return None else: raise NotImplementedError() def bool_to_oui_non(v: bool): if v == True: return "oui" elif v == False: return "non" elif v == None: return None else: raise NotImplementedError() oui_non_type = SpecialType( destination_type=bool, destination_to_source=bool_to_oui_non, source_to_destination=oui_non_to_bool )
Let’s assume that the source contains the following entities:
[ { "field_foo": "1", "field_bar": "1", "field_bool_converted": "oui" }, { "field_foo": "1", "field_bar": "1", "field_bool_converted": "non" }, { "field_foo": "1", "field_bar": "2", "field_bool_converted": null } ]
A read will therefore return a result of this form :
[ { "field_foo": "1", "field_bar": "1", "field_bool_converted": true }, { "field_foo": "1", "field_bar": "1", "field_bool_converted": false }, { "field_foo": "1", "field_bar": "2", "field_bool_converted": null } ]
And the entity type interface will be changed accordingly (field_bool_converted will be of type bool).
The recast is also applied on the filters, the creation body, the update body and ids, and the delete ids.
- field params: RecastTypeParams [Required][source]
RecastType proxy settings.
- async create(
- params: CreateParams,
Recast fields from destination type to source type. Then sends the query to the next proxy.
- Parameters:
params (CreateParams) –
- async delete(
- params: DeleteParams,
Recast id fields from destination type to source type. Then sends the query to the next proxy.
- Parameters:
params (DeleteParams) –
- async read(
- params: ReadParams,
Recast filters from destination type to source type. Sends the query to the next proxy. Then recasts the result fields from the source type to the destination type, before returning the result.
- Parameters:
params (ReadParams) –
- Return type:
list[Any]
- async update(
- params: UpdateParams,
Recast update fields and id fields from destination type to source type. Then sends the query to the next proxy.
- Parameters:
params (UpdateParams) –
- pydantic model crudcreator.proxy.proxy.type.RecastType.RecastTypeParams[source]
RecastType proxy settings.
- field list_recast_field: list[FieldRecast] [Required][source]
List of recasts to do.
- property recast_index: dict[str, SpecialType][source]
A field_name->special_type index built automatically from list_recast_field.
- pydantic model crudcreator.proxy.proxy.type.RecastType.FieldRecast[source]
-
- field special_type: SpecialType [Required][source]
The new type.
- pydantic model crudcreator.proxy.proxy.type.SpecialType.SpecialType[source]
- Validators:
- field destination_to_source: Any [Required][source]
The function that reprocesses the destination-side field to set it to the correct source-side type.
- Validated by:
- field source_to_destination: Any [Required][source]
The function that reprocesses fields on the source side to set them to the correct type on the destination side.
- Validated by:
- validator callable_type » source_to_destination, destination_to_source[source]
AddFilter
- pydantic model crudcreator.proxy.proxy.AddFilter.AddFilter[source]
Adds hard-coded filter instances to the read CRUD request.
Example of descriptor, which will return, to the user executing a read, only those entities whose “can_be_seen” field is set to True:
{ "name": "AddFilter", "params": { "list_filter_instance_to_add": [ { "field_name": "can_be_seen", "filter_value": true, "filtration_type": "equal" } ] } }
- field params: AddFilterParams [Required][source]
AddFilter proxy parameters.
- async read(
- params: ReadParams,
Adds the list of filter instances to the CRUD request, then forwards the request to the next proxy.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- pydantic model crudcreator.proxy.proxy.AddFilter.AddFilterParams[source]
AddFilter proxy parameters.
- field list_filter_instance_to_add: list[FilterInstance] [Required][source]
The list of filter instances to be added.
SoftDelete
- pydantic model crudcreator.proxy.proxy.SoftDelete.SoftDelete[source]
Transforms the delete into a “soft delete”. The delete thus becomes an update on fields that will indicate whether or not the entity should be considered as deleted.
Example of descriptor, which, when read, only returns entities where is_active!=false and is_deleted!=true. The “is_active” value of each entity will remain visible on reading (but not that of the “is_deleted” field, which therefore does not exist in the eyes of the CRUD user).
{ "name": "SoftDelete", "params": { "list_field_value_if_deleted": [ { "field_name": "is_active", "value_if_deleted": false, "keep_visible": true }, { "field_name": "is_deleted", "value_if_deleted": true, "keep_visible": false } ] } }
- field params: SoftDeleteParams [Required][source]
SoftDelete proxy settings.
- async delete(
- params: DeleteParams,
The delete becomes an update of the fields indicating deletion.
- Parameters:
params (DeleteParams) –
- async read(
- params: ReadParams,
We only read entities that have not been soft deleted.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- pydantic model crudcreator.proxy.proxy.SoftDelete.SoftDeleteParams[source]
SoftDelete proxy settings.
- field list_field_value_if_deleted: list[FieldValueIfDeleted] [Required][source]
List of fields/values that indicate that the entity is deleted. This is an “OR” for reading: if only one of the fields has the value “value_if_deleted”, then the field is considered deleted. On the other hand, “delete” will set all the fields in the list to the correct value.
- property value_if_deleted_index: dict[str, FieldValueIfDeleted][source]
Index field_name->FieldValueIfDeleted automatically created from list_field_value_if_deleted.
- pydantic model crudcreator.proxy.proxy.SoftDelete.FieldValueIfDeleted[source]
- field field_name: str [Required][source]
The field whose value determines whether an entity is deleted or not.
AddOptions
- pydantic model crudcreator.proxy.proxy.AddOptions.AddOptions[source]
Adds options to the interface.
Example of descriptor, which adds two read options, “limit” and “offset”, as well as an update option:
{ "name": "AddOptions", "params": { "list_read_options": [ { "name": "limit", "type": "int", "default": null, "is_mandatory": false }, { "name": "offset", "type": "int", "default": null, "is_mandatory": false } ], "list_updator_options": [ { "name": "add_update_date", "type": "bool", "default": true, "is_mandatory": false } ] } }
- field params: AddOptionsParams [Required][source]
AddOptions proxy settings.
- pydantic model crudcreator.proxy.proxy.AddOptions.AddOptionsParams[source]
AddOptions proxy settings.
- field list_creator_options: list[OptionModel] = [][source]
The list of options that will be requested from the CRUD user for create.
- field list_deletor_options: list[OptionModel] = [][source]
The list of options the CRUD user will be asked to delete.
- field list_read_options: list[OptionModel] = [][source]
The list of options that will be requested from the CRUD user for the read.
- field list_updator_options: list[OptionModel] = [][source]
The list of options that will be requested from the CRUD user for the update.
AddDefault
- pydantic model crudcreator.proxy.proxy.AddDefault.AddDefault[source]
Adds default values to certain fields.
Example of descriptor, which will add the default value of 10 to the “field_foo” field:
{ "name": "AddDefault", "params": { "default_on_fields": [ { "field_name": "field_foo", "default": 10 } ] } }
- field params: AddDefaultParams [Required][source]
AddDefault proxy settings.
- pydantic model crudcreator.proxy.proxy.AddDefault.AddDefaultParams[source]
AddDefault proxy settings.
- field default_on_fields: list[DefaultOnField] [Required][source]
List of default fields/values to be given.
- property default_index: dict[str, list[FilterType]][source]
Index field_name->default automatically created from default_on_fields.
AddWriteValue
- pydantic model crudcreator.proxy.proxy.AddWriteValue.AddWriteValue[source]
Adds hard-coded values to creation or update.
Example of descriptor, which adds a new value at creation (creation date), and a new value at update (the update date):
{ "name": "AddWriteValue", "params": { "list_create_value": [ { "name": "creation_date", "value": "$now$" } ], "list_update_value": [ { "name": "last_update_date", "value": "$now$" } ] } }
With “now” a substitution defined as follows:
"now": datetime.now
- field params: AddWriteValueParams [Required][source]
AddWriteValue proxy parameters.
- async create(
- params: CreateParams,
Adds the new values to the CRUD request, then forwards the request to the next proxy.
- Parameters:
params (CreateParams) –
- async update(
- params: UpdateParams,
Adds the new values to the CRUD request, then forwards the request to the next proxy.
- Parameters:
params (UpdateParams) –
AddIdValue
- pydantic model crudcreator.proxy.proxy.AddIdValue.AddIdValue[source]
Adds hard-coded ids to CRUD update and delete requests. The ids are used to select the entity to be updated or deleted.
Example of descriptor :
{ "name": "AddIdValue", "params": { "list_ids_value": [ { "name": "field_1", "value": 1 } ] } }
- field params: AddIdValueParams [Required][source]
AddIdValue proxy settings.
- async delete(
- params: DeleteParams,
Adds the ids to the CRUD request, then forwards the request to the next proxy.
- Parameters:
params (DeleteParams) –
- async update(
- params: UpdateParams,
Adds the ids to the CRUD request, then forwards the request to the next proxy.
- Parameters:
params (UpdateParams) –
GroupBy
- pydantic model crudcreator.proxy.proxy.GroupBy.GroupBy[source]
Has more or less the same effect as a SQL “group by” accompanied by a “GROUP_CONCAT”. Groups entities by distinct values of fields appearing in grouped_by_fields, and groups all entities with these values in a list.
Not to be confused with the “GatherField” proxy.
Example of descriptor. Group by field_foo and field_bar, and collects the list of entities in the “my_group” field:
{ "name": "GroupBy", "params": { "group_name": "my_group", "grouped_by_fields": ["field_foo", "field_bar"], "one_elem_with_all_none_means_empty": true, "see_group_only_on_option": "extend_group" } }
Let’s assume that the source contains the following entities:
[ { "field_foo": "1", "field_bar": "1", "other_field": "a", "other_field_2": "b" }, { "field_foo": "1", "field_bar": "1", "other_field": "c", "other_field_2": "d" }, { "field_foo": "1", "field_bar": "2", "other_field": "a", "other_field_2": "b" } ]
A read will therefore return a result of this form :
[ { "field_foo": "1", "field_bar": "1", "my_group": [ { "other_field": "a", "other_field_2": "b" }, { "other_field": "c", "other_field_2": "d" } ] }, { "field_foo": "1", "field_bar": "2", "my_group": [ { "other_field": "a", "other_field_2": "b" } ] } ]
- field params: GroupByParams [Required][source]
GroupBy proxy settings.
- async read(
- params: ReadParams,
Builds the list of fields to be read, depending on whether the option is enabled. Sends the request to the next proxy. Then groups the entities as required, before returning the result.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- pydantic model crudcreator.proxy.proxy.GroupBy.GroupByParams[source]
GroupBy proxy settings.
- field group_name: str [Required][source]
The name of the list that will contain all the other fields.
- field one_elem_with_all_none_means_empty: bool [Required][source]
If there is only one element in the list, and all the attributes of this element are set to None, then the list is considered empty. (to manage outer joins)
GatherFields
- pydantic model crudcreator.proxy.proxy.GatherFields.GatherFields[source]
Groups several fields from the same entity into a single object field. Not a “group by” as understood in SQL. The group will therefore be an object and not a list. Not to be confused with the “GroupBy” proxy.
Example of descriptor. Gathers field_foo and field_bar into a single field named “my_group”
{ "name": "GatherFields", "params": { "group_name": "my_group", "gathered_fields": ["field_foo", "field_bar"], "see_group_only_on_option": "extend_group" } }
Let’s assume that the source contains the following entities:
[ { "field_foo": "1", "field_bar": "1", "other_field": "a", "other_field_2": "b" }, { "field_foo": "1", "field_bar": "1", "other_field": "c", "other_field_2": "d" }, { "field_foo": "1", "field_bar": "2", "other_field": "a", "other_field_2": "b" } ]
A read will therefore return a result of this form :
[ { "other_field": "a", "other_field_2": "b", "my_group": [ { "field_foo": "1", "field_bar": "1" } ] }, { "other_field": "c", "other_field_2": "d", "my_group": [ { "field_foo": "1", "field_bar": "1" } ] }, { "other_field": "a", "other_field_2": "b" "my_group": [ { "field_foo": "1", "field_bar": "2" } ] } ]
- field params: GatherFieldsParams [Required][source]
GatherFields proxy settings.
- async read(
- params: ReadParams,
Builds the list of fields to be read, depending on whether the option is enabled. Sends the request to the next proxy. Then groups the entities as required, before returning the result.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- pydantic model crudcreator.proxy.proxy.GatherFields.GatherFieldsParams[source]
GatherFields proxy settings.
- field gathered_fields: list[str] [Required][source]
The list of field names to be collected in the group.
Firewalls
ReadFirewall
- pydantic model crudcreator.proxy.proxy.ReadFirewall.ReadFirewall[source]
Whitelists the fields that can be read by the CRUD user. Set can_be_read to False for other interface fields.
Example of descriptor, which makes only the “field_foo” and “field_bar” fields visible for reading:
{ "name": "ReadFirewall", "params": { "list_readable_field_name": [ "field_foo", "field_bar" ] } }
- field params: ReadFirewallParams [Required][source]
ReadFirewall proxy settings.
- async read(
- params: ReadParams,
Checks that the fields to be read, given in the CRUD request, are indeed part of the whitelist.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
CreateFirewall
- pydantic model crudcreator.proxy.proxy.CreateFirewall.CreateFirewall[source]
Whitelists the fields that can be filled in when an entity is created by the CRUD user. Set can_be_created to False for other interface fields.
Example of descriptor, which allows only the “field_foo” and “field_bar” fields to be filled at creation:
{ "name": "CreateFirewall", "params": { "list_creatable_field_name": [ "field_foo", "field_bar" ] } }
- field params: CreateFirewallParams [Required][source]
CreateFirewall proxy settings.
- async create(
- params: CreateParams,
Checks that the fields entered in the CRUD request are part of the whitelist.
- Parameters:
params (CreateParams) –
- Return type:
list[dict[str, Any]]
UpdateFirewall
- pydantic model crudcreator.proxy.proxy.UpdateFirewall.UpdateFirewall[source]
Whitelists the fields that can be filled in when an entity is updated by the CRUD user. Set can_be_updated to False for other interface fields.
Example of descriptor, which allows only the “field_foo” and “field_bar” fields to be filled at update:
{ "name": "UpdateFirewall", "params": { "list_updatable_field_name": [ "field_foo", "field_bar" ] } }
- field params: UpdateFirewallParams [Required][source]
UpdateFirewall proxy settings.
- async update(
- params: UpdateParams,
Checks that the fields entered in the CRUD request are part of the whitelist.
- Parameters:
params (UpdateParams) –
- Return type:
list[dict[str, Any]]
FilterFirewall
- pydantic model crudcreator.proxy.proxy.FilterFirewall.FilterFirewall[source]
Whitelists filters that can be set by the CRUD user during the read. Modifies list_allowed_filter_type of fields in the interface.
Example of descriptor, which allows a “contain” filter on “field_foo” and an “equal” filter on “field_bar”:
{ "name": "FilterFirewall", "params": { "allowed_filter_on_fields": [ { "field_name": "field_foo", "allowed_filter_type": { "filtration_type": "contain", "is_mandatory": false, "default": null } }, { "field_name": "field_bar", "allowed_filter_type": { "filtration_type": "equal", "is_mandatory": true, "default": null } } ] } }
- field params: FilterFirewallParams [Required][source]
FilterFirewall proxy settings.
- async read(
- params: ReadParams,
Does nothing for now. TODO: add validation.
- Parameters:
params (ReadParams) –
- Return type:
list[dict[str, Any]]
- pydantic model crudcreator.proxy.proxy.FilterFirewall.FilterFirewallParams[source]
FilterFirewall proxy settings.
- field allowed_filter_on_fields: list[AllowedFilterOnField] [Required][source]
The list of filters that the CRUD user can fill in when reading.
- property allowed_filter_type_index: dict[str, list[FilterType]][source]
Index field_name->allowed_filter_type automatically created from allowed_filter_on_fields.
Links
CreateLink
- pydantic model crudcreator.proxy.proxy.link.CreateLink.CreateLink[source]
Creates a link with another entity type. Only change the interface of the current entity type. Does not change any CRUD actions. Must therefore be used with other proxies, which will implement a way of handling these links (for example, CascadeDelete or CascadeCreateAndUpdate proxies).
Example of a descriptor linking the current entity with the “entity_bis” entity on the “field_to_join” and “field_to_be_joined”, in one-to-one mode:
{ "name": "CreateLink", "params": { "interface_merge": true, "list_linked_field": [ { "field_name": "field_to_join", "link": { "entity_type_linked_to": "$entity_bis$", "field_name_linked_to": "field_to_be_joined", "type": { "source": { "min": "one", "max": "one" }, "dest": { "min": "one", "max": "one" } } } } ] } }
- field params: CreateLinkParams [Required][source]
CreateLink proxy settings.
- pydantic model crudcreator.proxy.proxy.link.CreateLink.CreateLinkParams[source]
CreateLink proxy settings.
- field list_linked_field: list[LinkedField] [Required][source]
List of links.
CascadeDelete
- pydantic model crudcreator.proxy.proxy.link.CascadeDelete.CascadeDelete[source]
Changes the delete into a “cascade delete”. Changes the delete behavior if the current entity is linked to another entity, and the destination entity must be linked to one and only one source entity (one-to-* link). In this case, if the current entity is deleted, destination entities linked to the current deleted entity are also deleted. Must be preceded by at least one CreateLink to specify links.
Example of descriptor :
{ "name": "CascadeDelete", "params": {} }
Which could be preceded by the following descriptor:
{ "name": "CreateLink", "params": { "interface_merge": true, "list_linked_field": [ { "field_name": "field_to_join", "link": { "entity_type_linked_to": "$entity_bis$", "field_name_linked_to": "field_to_be_joined", "type": { "source": { "min": "one", "max": "one" }, "dest": { "min": "one", "max": "one" } } } } ] } }
- field params: CascadeDeleteParams [Required][source]
CascadeDelete proxy settings.
- async delete(
- params: DeleteParams,
Scans all links of the entity type, and if the link has the correct cardinality, deletes the linked destination entities. Then deletes the current entity.
- Raises:
EntityNotExist – If the destination entity, to which the deleted source is linked, does not exist, while the link stipulates that the source must be linked to at least one destination.
- Parameters:
params (DeleteParams) –
CascadeCreateAndUpdate
- pydantic model crudcreator.proxy.proxy.link.CascadeCreateAndUpdate.CascadeCreateAndUpdate[source]
Changes the create and update into a “cascade create” or “cascade update”. Changes the create and update behavior if the current entity is linked to another entity, and the source entity must be linked to one and only one destination entity (*-to-one link). In this case, if the current entity is updated, destination entities linked to the current updated entity are also updated. Likewise, if the current entity is created, a new destination entities linked to the current created entity is also created.
Example of descriptor :
{ "name": "CascadeCreateAndUpdate", "params": {} }
Which could be preceded by the following descriptor:
{ "name": "CreateLink", "params": { "interface_merge": true, "list_linked_field": [ { "field_name": "field_to_join", "link": { "entity_type_linked_to": "$entity_bis$", "field_name_linked_to": "field_to_be_joined", "type": { "source": { "min": "one", "max": "one" }, "dest": { "min": "one", "max": "one" } } } } ] } }
- field params: CascadeCreateAndUpdateParams [Required][source]
CascadeCreateAndUpdate proxy settings.
- async create(
- params: CreateParams,
Scans all links of the entity type, and if the link has the correct cardinality, creates a linked destination entities. Then creates the current entity.
Warning
Works only if the foreign key is specified in dict_creator_value.
- Parameters:
params (CreateParams) –
- async update(
- params: UpdateParams,
Scans all links of the entity type, and if the link has the correct cardinality, updates the linked destination entities. Then updates the current entity.
- Parameters:
params (UpdateParams) –